Advertisement
Blessing988

Untitled

Feb 29th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. # This program declares a function that accepts two parameters, a_list and number and returns a new list with words that have a length equal to the number
  2.  
  3. #function
  4.  
  5. def right_words(a_list, number):
  6.     items = [ ]
  7.     for item in a_list:
  8.         if len(item)==number:
  9.             items.append(item)
  10.     print(items)
  11.  
  12. right_words(["cat", "dog", "bean", "ace"], 3) # Example (the first argument must be a list consisting of words, the 2nd argument must be a number)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement