Skip to content

Instantly share code, notes, and snippets.

@cibofdevs
Last active September 19, 2022 13:09
Show Gist options
  • Save cibofdevs/45ce3c620da9714379044dbdce441744 to your computer and use it in GitHub Desktop.
Save cibofdevs/45ce3c620da9714379044dbdce441744 to your computer and use it in GitHub Desktop.
# 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"
original_list = list(original_str.split())
num_words = len(original_list)
num_words_list = []
for i in original_list:
num_words_list.append((len(i)))
print(num_words_list)
@mattmaciel
Copy link

Even more simplest:
num_words_list = []
original_str = "The quick brown rhino jumped over the extremely lazy fox"
for word in original_str.split():
num_words_list.append(len(word))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment