Advertisement
ganiyuisholaafeez

count() with lambda and map

Feb 29th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. """ A program that returns a list of times the character a appears in a list of words """
  2. # For flexibility, user is expected to type words where comma is used as
  3. # as a delimiter between every two word
  4. type_words = input("Enter your list of word and use a comma and whitespace \
  5. as a separator between two word: ")
  6. word = type_words.split(", ") # The splits the words to a list
  7.  
  8. # The count_of_a function declaration
  9. def count_of_a(words):
  10.     print(list(map(lambda word: word.count("a"), words)))
  11.  
  12. # The function invocation
  13. count_of_a(word)
  14.  
  15.  
  16. # Enter your list of word and use a comma and whitespace as a separator between
  17. # two word: alligator, aardvark, albatross
  18. # [2, 3, 2]
  19.  
  20. # Enter your list of word and use a comma and whitespace as a separator between
  21. # two word: plywood
  22. # [0]
  23.  
  24. # Enter your list of word and use a comma and whitespace as a separator between
  25. # two word:
  26. # [0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement