Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This program declares a function that accepts a list of strings and returns the number of times letter "a" occurs in an element of the list
- # function
- def count_of_a(a_list_of_strings):
- new_list = [ ]
- for word in a_list_of_strings:
- if "a" in word:
- new_list.append(word.count("a")) # This syntax will append to the "new_list" the number of times "a" occurs in a word
- else:
- new_list.append(0)
- print(new_list)
- count_of_a(["alligator", "aadvark", "albatross"])
- count_of_a([ ]) # Examples( The argument must be a list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement