Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ This code accepts a list of words and a number and it returns only a list of words that has the length of the number specified"""
- # For flexibility, user is expected to type words where comma is used as
- # as a delimiter between every two word
- type_words = input("Enter your list of word and use a comma and whitespace\
- as a separator between two word: ")
- list_of_words = type_words.split(", ") # The splits the words to a list
- # The length to be considered is typed in by the user
- no_of_character = int(input("Enter the choosen length to consider: "))
- # right_words function declaration
- def right_words(words, number):
- print(list(filter(lambda word: len(word) == number, words)))
- # Invocation of the right_words function
- right_words(list_of_words, no_of_character)
- # Enter your list of word and use a comma and whitespaceas a separator between two word:
- # cat, dog, bean, ace, heart
- # Enter the choosen length to consider: 3
- # ['cat', 'dog', 'ace']
- # Enter your list of word and use a comma and whitespaceas a separator between two word:
- # cat, dog, bean, ace, heart
- # Enter the choosen length to consider: 5
- # ['heart']
- # Enter your list of word and use a comma and whitespaceas a separator between two word
- # Enter the choosen length to consider: 4
- # []
Add Comment
Please, Sign In to add comment