8000 Merge pull request #35 from etienne-napoleone/patch-1 · AllAlgorithms/python@02ffd4d · GitHub
[go: up one dir, main page]

Skip to content

Commit 02ffd4d

Browse files
authored
Merge pull request #35 from etienne-napoleone/patch-1
Use `in` for substring check
2 parents a469aab + 78ab31e commit 02ffd4d

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