list subsetting

Paul Rubin http
Wed Jan 21 17:19:54 EST 2009


culpritNr1 <ig2ar-saf1 at yahoo.co.uk> writes:
> a = [0 , 1, 3.14, 20, 8, 8, 3.14]
> 
> Is there a simple python way to count the number of 3.14's in the list in
> one statement?

n = sum(1 for x in a if x == 3.14)



More information about the Python-list mailing list