Skip to content

Instantly share code, notes, and snippets.

@NamrataSitlani
Last active August 25, 2020 19:47
Show Gist options
  • Save NamrataSitlani/5fcd06e2656b8e27db351e16eda6058c to your computer and use it in GitHub Desktop.
Save NamrataSitlani/5fcd06e2656b8e27db351e16eda6058c to your computer and use it in GitHub Desktop.
Given a string s and a character c, return the number of occurrences of c in s.
def numChars(string, word):
count = 0
for i in list(string):
if word in i:
count+= 1
print(count)
numChars("oh heavens", "h")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment