list subsetting

James Mills prologic at shortcircuit.net.au
Wed Jan 21 20:53:36 EST 2009


On Thu, Jan 22, 2009 at 11:35 AM, blueiur <blueiur at gmail.com> wrote:
> i think it's best way
> lst = [0, 1, 3.14, 20, 8, 8, 3.14]
> len( filter(lambda x: x > 3.13 and x < 3.15, lst) )
> 2

I prefer this way (cleaner):

>>> lst = [0, 1, 3.14, 20, 8, 8, 3.14]
>>> len([x for x in lst if 3.13 < x < 3.15])
2
>>>

cheers
James



More information about the Python-list mailing list