Question
A problem you are trying to solve has a Python string named lorem that has been split word-by-word using the string split() method with an
A problem you are trying to solve has a Python string named lorem that has been split word-by-word using the string split() method with an argument sep = ' ' to create a new list named lorem_words, as seen in the starter code below. You have been asked to do the following:
Search for the documentation of the string split() method. Then write a brief description of the string split() method as Python comments. Your description must contain (1) what split() does, (2) syntax of split(), and (3) what are the arguments (indicate required or optional) and what they do. Lastly, in your own words, explain how the variable lorem_words got its value after running the first two lines of the starter code based on your description of the string split() method.
Create a new dictionary named word_len.
Use a for loop with a sorted() statement (ascending order) for your lorem_words list.
Inside your for loop statement, add key-value pairs to your new dictionary named word_len, using each word in the lorem_words list as the dictionary key, and the dictionary value being the length of the word (= number of characters) being added to your dictionary named word_len.
The last line of your script has a print(word_len) statement that will provide the sample output below.
Strater Code
lorem = 'ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi aliquip' lorem_words = lorem.split(sep=' ')
print(lorem_words)
### (EXPLAIN IN YOUR OWN WORDS, HOW lorem_words GOT ITS VALUE)
Print(word_len)
Expected output
{'ad': 2, 'aliquip': 7, 'enim': 4, 'exercitation': 12, 'laboris': 7, 'minim': 5,
'nisi': 4, 'nostrud': 7, 'quis': 4, 'ullamco': 7, 'ut': 2, 'veniam': 6}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started