Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ This function returns every element in a list that has 5 or more characters """
- def long_strings(list_of_strings):
- new_list = [] # An empty list
- for list_of_string in list_of_strings:
- if len(list_of_string) >= 5: # Testing the no of characters
- new_list.append(list_of_string)
- return new_list
- print(long_strings(["Hello", "Goodbye", "Sam"])) # ['Hello', 'Goodbye']
- print(long_strings(["Ace", "Cat", "Job"])) # []
- print(long_strings([])) # []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement