Re: list subsetting

2009-01-21 Thread James Mills
On Thu, Jan 22, 2009 at 11:35 AM, blueiur 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 J

Re: list subsetting

2009-01-21 Thread blueiur
o 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

Re: list subsetting

2009-01-21 Thread MRAB
culpritNr1 wrote: Thank you Fogelbird and Jeff. I actually tried to find out if such function existed. I did help("count") no Python documentation found for 'count' [snip] 'count' is a method of the list class, so you need: help(list.count) and if you want help on the list class then it's

Re: list subsetting

2009-01-21 Thread FogleBird
On Jan 21, 5:22 pm, culpritNr1 wrote: > Thank you Fogelbird and Jeff. > > I actually tried to find out if such function existed. I did > > >>> help("count") > > no Python documentation found for 'count' > > Anyway. More than counting, I am

Re: list subsetting

2009-01-21 Thread Robert Kern
culpritNr1 wrote: Thank you Fogelbird and Jeff. I actually tried to find out if such function existed. I did help("count") no Python documentation found for 'count' Anyway. More than counting, I am interested in list subsetting in a simple way. Forget about counting.

Re: list subsetting

2009-01-21 Thread Paul Rubin
culpritNr1 writes: > Anyway. More than counting, I am interested in list subsetting in a simple > way. Forget about counting. Say I have a list of lists and I want to pull > only the rows where the second "column" equals 3.14. list_of_lists = [[1.414,2.718,3.14],[4.00,3.

Re: list subsetting

2009-01-21 Thread culpritNr1
Thank you Fogelbird and Jeff. I actually tried to find out if such function existed. I did >>> help("count") no Python documentation found for 'count' Anyway. More than counting, I am interested in list subsetting in a simple way. Forget about counting. Say I have

Re: list subsetting

2009-01-21 Thread Jervis Whitley
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 - pytho

Re: list subsetting

2009-01-21 Thread Paul Rubin
culpritNr1 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) -- http://mail.python.org/mailman/listinfo/python-list

Re: list subsetting

2009-01-21 Thread Rob Williscroft
culpritNr1 wrote in news:mailman.7713.1232574803.3487.python-l...@python.org in comp.lang.python: > > 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

Re: list subsetting

2009-01-21 Thread bearophileHUGS
FogleBird: > a.count(3.14) If the values to count are approximated FP values, then you may need something more complex, like: leniter(ifilter(somefunction, a)) Where somefunction uses an approximated comparison, and leniter is just a function that counts the items of a generic iterator. Bye, be

Re: list subsetting

2009-01-21 Thread Jeff McNeil
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 >

Re: list subsetting

2009-01-21 Thread FogleBird
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 >

list subsetting

2009-01-21 Thread culpritNr1
(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. --