Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. # A fucntion that checks the length of each word in a list and returns a new list depending on the condition
  2. def right_words(word): #define the function
  3. return len(word)==3 #state a condition which must be True for any of the element in the list
  4.  
  5. words = ['cat', 'dog','bean','ace', 'heart'] # assign list to a variable
  6.  
  7. #use the filter function to apply the function defined above to the list
  8. #and then convert it to a list
  9. print(list(filter(right_words,words)))
  10. def right_words(word):
  11. return len(word)==5
  12. words = ['cat', 'dog','bean','ace', 'heart']
  13.  
  14. print(list(filter(right_words,words)))
  15.  
  16. def right_words(word):
  17. return len(word)==4
  18. words = []
  19. print(list(filter(right_words,words)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement