O'Reilly logo
  • Vlad Bezden thinks this is interesting:

number_of_vowels = len(filter(lambda letter: letter in 'aeiou', s))


Cover of Serious Python


This line doesn't work because a filter is a generator and len function can't be applied to the generator. Instead, list comprehension can be used:

number_of_vowels = len([letter for letter in s if letter in "aeiou"])