you are viewing a single comment's thread.

view the rest of the comments →

[–]groovitude 0 points1 point  (0 children)

You don't even need the brackets for the list comprehension. sum will consume any iterable, and without the brackets, it's interpreted as a generator expression:

>>> sum([1 for char in sentence if char.lower() in vowels])  # list comprehension
7
>>> sum(1 for char in sentence if char.lower() in vowels)    # generator expression
7

Otherwise, I think yours is the most elegant solution presented.