3 ms·
Perhaps a for-loop is more similar to your memory of other code, but a list comprehension is more similar to an English sentence. "All names longer than 4
by msellout 11y ago
Perhaps a for-loop is more similar to your memory of other code, but a list comprehension is more similar to an English sentence.
"All names longer than 4 characters in the list of cities?"
all(len(name) > 4 for name in cities)
"Sum of x-squared for x from 10 to 20."
sum(x**2 for x in range(10, 20))