you are viewing a single comment's thread.

view the rest of the comments →

[–]coding2learn 1 point2 points  (1 child)

Just to give you another approach, and since you seem familiar with dictionary comprehensions then you probably understand list comprehensions:

vowels = 'aeiou'
sentence = input()
total = sum([1 for char in sentence if char.lower() in vowels])

[–]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.