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
On 1월22일, 오전6시53분, culpritNr1 <ig2ar-s...@yahoo.co.uk> wrote: > Hello All, > > Say I have a list like this: > > 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? > > In R I do like this > > a = c(0 , 1, 3.14, 20, 8, 8, 3.14) > > length( a[ a[]==3.14 ] ) > > How do I do that in standard python? > > (Note that this is just an example, I do not mean to use == in floating > point operations.) > > Thank you > > culpritNr1 > > -- > View this message in > context:http://www.nabble.com/list-subsetting-tp21593123p21593123.html > Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list