Tom Ritchford
1 min readMay 23, 2020

--

Even more readable is this, I think:

return len({i for i in x if i in 'aeiou'})

People remember list and dict comprehensions but forget that set comprehensions have always been available.

Another possibility:

return len(set('aeiou').intersection(x))))

It’s a tiny bit shorter and probably a bit faster because there’s no (Python) loop. On different days I might make different choices.

Thanks for an interesting series that I’ve been reading with great pleasure!

--

--

Responses (1)