Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create a list of word lengths for the words in original_str using the accumulation pattern

Tags:

python

list

The questions is this:

Write code to create a list of word lengths for the words in original_str using the accumulation pattern and assign the answer to a variable num_words_list. (You should use the len function).

original_str = "The quick brown rhino jumped over the extremely lazy fox".split()
original_list = list(original_str)
num_words = len(original_list)
for i in original_list:
    print(len(i))

This is my output but it needs to be as a list and in the num_words_list variable, but I can't seem to convert it.

3 5 5 5 6 4 3 9 4 3

like image 577
Lefteris Theodorou Avatar asked Nov 30 '25 04:11

Lefteris Theodorou


1 Answers

Without giving too much away:

  1. Create an empty list before your loop
  2. Instead of calling print on each item, add the item to the list.

Both steps should be quite easy to find online.

Good luck!

like image 181
Bart Friederichs Avatar answered Dec 02 '25 16:12

Bart Friederichs