Advertisement
ganiyuisholaafeez

Untitled

Feb 22nd, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. """ This function returns every element in a list that has 5 or more characters """
  2. def long_strings(list_of_strings):
  3.     new_list = []                       # An empty list
  4.     for list_of_string in list_of_strings:
  5.         if len(list_of_string) >= 5:   # Testing the no of characters
  6.             new_list.append(list_of_string)
  7.     return new_list
  8.  
  9. print(long_strings(["Hello", "Goodbye", "Sam"])) # ['Hello', 'Goodbye']
  10. print(long_strings(["Ace", "Cat", "Job"])) # []
  11. print(long_strings([])) # []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement