Re: help with list comprehension

2008-05-02 Thread Yves Dorfsman
George Sakkis wrote: Another alternative is: from operator import itemgetter def m3(): colours, nums = zip(*map(itemgetter('colour','num'), l)) It's slower than m1() but faster than m2(); it's also the most concise, especially if you extract more than two keys. Good you guys gave me som

Re: help with list comprehension

2008-05-02 Thread George Sakkis
On May 2, 2:17 am, Matimus <[EMAIL PROTECTED]> wrote: > On May 1, 10:50 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > > > > > On May 1, 11:46 pm, Carsten Haese <[EMAIL PROTECTED]> wrote: > > > > Yves Dorfsman wrote: > > > > > In the following script, m1() and m2() work fine. I am assuming m2() is

Re: help with list comprehension

2008-05-01 Thread Matimus
On May 1, 10:50 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > On May 1, 11:46 pm, Carsten Haese <[EMAIL PROTECTED]> wrote: > > > > > Yves Dorfsman wrote: > > > > In the following script, m1() and m2() work fine. I am assuming m2() is > > > faster although I haven't checked that (loops through the

Re: help with list comprehension

2008-05-01 Thread George Sakkis
On May 1, 11:46 pm, Carsten Haese <[EMAIL PROTECTED]> wrote: > Yves Dorfsman wrote: > > > In the following script, m1() and m2() work fine. I am assuming m2() is > > faster although I haven't checked that (loops through the list twice > > instead of once). > > Well, let's check it: > > $ python -m

Re: help with list comprehension

2008-05-01 Thread Karthik Gurusamy
On May 1, 8:01 pm, Yves Dorfsman <[EMAIL PROTECTED]> wrote: > In the following script, m1() and m2() work fine. I am assuming m2() is > faster although I haven't checked that (loops through the list twice instead > of once). > > Now what I am trying to do is something like m3(). As currently writte

Re: help with list comprehension

2008-05-01 Thread Carsten Haese
Yves Dorfsman wrote: In the following script, m1() and m2() work fine. I am assuming m2() is faster although I haven't checked that (loops through the list twice instead of once). Well, let's check it: $ python -m timeit -s "import x" "x.m1()" 10 loops, best of 3: 6.43 usec per loop $

help with list comprehension

2008-05-01 Thread Yves Dorfsman
In the following script, m1() and m2() work fine. I am assuming m2() is faster although I haven't checked that (loops through the list twice instead of once). Now what I am trying to do is something like m3(). As currently written it does not work, and I have tried different ways, but I have