Question

Solve in Python 3: Implement function four_letter() that takes as input a list of words (i.e.,...

Solve in Python 3: Implement function four_letter() that takes as input a list of words (i.e., strings) and returns the sublist of all four letter words in the list.

>>> four_letter(['dog', 'letter', 'stop', 'door', 'bus', 'dust'])

['stop', 'door', 'dust']

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code

def four_letter(wordList):
subList=[]#declare an empty list
#itreat through each word in the list
for word in wordList:
if(len(word)==4):#check the word length is 4 if it is 4 then append the word in sublist
subList.append(word)
return subList #return the subList

print(four_letter(['dog', 'letter', 'stop', 'door', 'bus', 'dust']))

output

code snaps

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
Solve in Python 3: Implement function four_letter() that takes as input a list of words (i.e.,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python Implement a program that requests from the user a list of words (i.e., strings) and...

    Python Implement a program that requests from the user a list of words (i.e., strings) and then prints on the screen, one per line, all four-letter strings in the list. >>> Enter word list: ['stop', 'desktop', 'top', 'post'] stop post

  • Implement a program that requests from the user a list of words (i.e., strings) and then...

    Implement a program that requests from the user a list of words (i.e., strings) and then prints on the screen, one per line, all four-letter strings in the list. >>> Enter word list: ['stop', 'desktop', 'top', 'post'] stop post An acronym is a word formed by taking the first letters of the words in a phrase and then making a word from them. For example, RAM is an acronym for random access memory. Write a function acronym() that takes a...

  • write a function firstLetterWords(words) that takes as a parameter a list of strings named words and...

    write a function firstLetterWords(words) that takes as a parameter a list of strings named words and returns a dictionary with lower case letters as keys. But now associate with each key the list of the words in words that begin with that letter. For example, if the list is ['ant', 'bee', 'armadillo', 'dog', 'cat'], then your function should return the dictionary {'a': ['ant', 'armadillo'], 'b': ['bee'], 'c': ['cat'], 'd': ['dog']}.

  • Write a function findEvens that takes an integer, n, as input and returns the list of...

    Write a function findEvens that takes an integer, n, as input and returns the list of even integers between 1 and n. Ex. Input: 10 Output: [2,4,6,8,10] Write a function sortList that takes in a list of strings and returns a list of those strings now sorted and lowercase. Ex. Input: [‘ABE’,’CAD’,’gaB’] Output: [‘abe’,’acd’,’abg’] Both done in Python

  • PYTHON Programming short Questions: 1. Write a function takes as input name (string) and age (number)...

    PYTHON Programming short Questions: 1. Write a function takes as input name (string) and age (number) and prints: My name is <name> and I am <age> years old(where name and age are the inputs) 2. Write a function that takes as input a and b and returns the result of: ??ab 3. Write a function that takes as input a and b and returns the result of: ??ab if it is valid to divide a and b 4. Write a...

  • Write a function called most_consonants(words) that takes a list of strings called words and returns the...

    Write a function called most_consonants(words) that takes a list of strings called words and returns the string in the list with the most consonants (i.e., the most letters that are not vowels). You may assume that the strings only contain lowercase letters. For example: >>> most_consonants(['python', 'is', 'such', 'fun']) result: 'python' >>> most_consonants(['oooooooh', 'i', 'see', 'now']) result: 'now' The function that you write must use a helper function (either the num_vowels function from lecture, or a similar function that you...

  • Write the function deep_contains. It takes as input a number and a list. That list might...

    Write the function deep_contains. It takes as input a number and a list. That list might contain lists as elements, and those lists might contain lists, etc. The deep_contains' function should return a Boolean indicating whether the number is contained inputted list, or a sublist of it, or a sublist of that, and so forth. For example: deep_contains (3, (1,3,5]) returns True deep_contains(3, 11, [3,5]]) returns True deep_contains (3, 1, [[3,4],5),6]) returns True deep_contains (2, (1,3,5]) returns False This function...

  • solve with python Write a recursive function recStringWithLenCount() that takes a one-dimensional list of strings as...

    solve with python Write a recursive function recStringWithLenCount() that takes a one-dimensional list of strings as a parameter and returns the count of strings that have at least the length of second parameter passed into the function that are found in the list. Recall that you can determine whether an item is a string by writing type(item) == str. The only list functions you are allowed to use are len(), indexing (lst[i] for an integer i), or slicing (lst[i:j] for...

  • IN PYTHON 3) Number of Words Write a function numWords() which takes in a string can...

    IN PYTHON 3) Number of Words Write a function numWords() which takes in a string can prints the number of words in the string. You can assume that words will only be separated with spaces, commas, and periods. "hello, world" -> 2 "this is cool" -> 3 4) Is Sorted Write a function isSorted() which takes in an list of integers and returns true if the numbers are sorted from smallest to largest.

  • (Python)Implement the function deep_list, which takes in a list, and returns a new list which contains...

    (Python)Implement the function deep_list, which takes in a list, and returns a new list which contains only elements of the original list that are also lists. Use a list comprehension. def deep_list(seq): "" "Returns a new list containing elements of the original list that are lists. >>> seq = [49, 8, 2, 1, 102] >>> deep_list(seq) [] >>> seq = [[500], [30, 25, 24], 8, [0]] >>> deep_list(seq) [[500], [30, 25, 24], [0]] >>> seq = ["hello", [12, [25], 24],...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT