8000 refactor(strings): use in for substring check · AllAlgorithms/python@78ab31e · GitHub
[go: up one dir, main page]

Skip to content

Commit 78ab31e

Browse files
refactor(strings): use in for substring check
1 parent 7afdd98 commit 78ab31e

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

strings/substring-check.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
# function to check if small string is
2-
# there in big string
3-
def check(string, sub_str):
4-
if (string.find(sub_str) == -1):
5-
print("NO")
6-
else:
7-
print("YES")
8-
9-
# driver code
10-
string = "" #Enter string
11-
sub_str ="" #Enter sub string
12-
check(string, sub_str)
1+
def substring_check(string, sub_str):
2+
return sub_str in string
3+
4+
string = "Hello everyone"
5+
sub_str_present ="llo e"
6+
sub_str_absent ="abcd"
7+
print(substring_check(string, sub_str_present)) # True
8+
print(substring_check(string, sub_str_absent)) # False

0 commit comments

Comments
 (0)
0