Last active
September 19, 2022 13:09
-
-
Save cibofdevs/45ce3c620da9714379044dbdce441744 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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))