noob question Letters in words?

Steven D'Aprano steve at REMOVETHIScyber.com.au
Sat Oct 8 05:24:04 CEST 2005


On Sat, 08 Oct 2005 13:19:48 +1000, Steven D'Aprano wrote:

> 
> def count_matches(s, words):
>     temp = [word.lower().startswith(s) for word in words]
>     return len(temp)


Oops! A *serious* bug in that code :-(

Replace "return len(temp)" with "return len(filter(None, temp))".

-- 
Steven.




More information about the Python-list mailing list