Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created April 28, 2020 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/61bd65a8701ec1efbb97bd6fddf09433 to your computer and use it in GitHub Desktop.
Save codecademydev/61bd65a8701ec1efbb97bd6fddf09433 to your computer and use it in GitHub Desktop.
Codecademy export
# Write your count_multi_char_x function here:
def count_multi_char_x(word,x):
item = word.split(x)
return (len(item)-1)
# Uncomment these function calls to test your tip function:
print(count_multi_char_x("mississippi", "iss"))
# should print 2
print(count_multi_char_x("apple", "pp"))
# should print 1
def count_multi_char_x1(word,x):
if x[0] not in word:
return 0
else:
index_of_first_letter = []
final_check = []
for a in range(len(word)):
if word[a] == x[0]:
index_of_first_letter.append(a)
for b in index_of_first_letter:
to_be_checked = True
counter123 = b
for c in range(1,len(x)):
counter123 += 1
if counter123 >=len(word[b:]):
to_be_checked = False
break
else:
if x[c] != word[int(counter123)]:
to_be_checked = False
final_check.append(to_be_checked)
return final_check.count(True)
# Uncomment these function calls to test your tip function:
print(count_multi_char_x1("mississippi", "iss"))
# should print 2
print(count_multi_char_x1("apple", "pp"))
# should print 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment