Advertisement
Blessing988

Untitled

Feb 29th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. #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
  2.  
  3. # function
  4.  
  5. def count_of_a(a_list_of_strings):
  6.     new_list = [ ]
  7.     for word in a_list_of_strings:
  8.         if "a" in word:
  9.             new_list.append(word.count("a"))    # This syntax will append to the "new_list" the number of times "a" occurs in a word
  10.         else:
  11.             new_list.append(0)
  12.     print(new_list)
  13.  
  14.  
  15. count_of_a(["alligator", "aadvark", "albatross"])
  16. count_of_a([ ])                                                     # Examples( The argument must be a list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement