Re: efficient intersection of lists with rounding

2004-12-06 Thread Gordon Williams
> Hi, > > I have to lists that I need to find the common numbers (2nd rounded to > nearest integral) and I am wondering if there is a more efficient way of > doing it. > > >>> a= [(123,1.3),(123,2.4),(123,7.8),(123,10.2)] > >>> b= [(123, 0.9), (123, 1.9), (123, 8.0)] > >>> [ (i,round(j)) for i,j

Re: efficient intersection of lists with rounding

2004-12-03 Thread Michael Hoffman
Steven Bethard wrote: Yeah, almost certainly since he's looking at lists 3K long. If they were small, you never know since the list comprehension gets the C-code speedup, while sets.Set is Python code: > [list comprehension] 1 loops, best of 3: 27.5 usec per loop > [Python 2.3 Set] 1 lo

Re: efficient intersection of lists with rounding

2004-12-03 Thread Raymond Hettinger
"Gordon Williams" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > > I have to lists that I need to find the common numbers (2nd rounded to > nearest integral) and I am wondering if there is a more efficient way of > doing it. > > >>> a= [(123,1.3),(123,2.4),(123,7.8),(123,10.2)]

Re: efficient intersection of lists with rounding

2004-12-02 Thread Steven Bethard
Michael Hoffman wrote: Steven Bethard wrote: Well, in Python 2.3, I believe sets are implemented in Python while they're implemented in C in Python 2.4. I think the Python 2.3 Sets implementation is likely to be quicker than whatever list-manipulation answer you come up with instead. But there's

Re: efficient intersection of lists with rounding

2004-12-02 Thread Adam DePrince
On Thu, 2004-12-02 at 22:16, Greg Ewing wrote: > Gordon Williams wrote: > a= [(123,1.3),(123,2.4),(123,7.8),(123,10.2)] > b= [(123, 0.9), (123, 1.9), (123, 8.0)] > [ (i,round(j)) for i,j in a for l,m in b if (i,round(j)) == > > (l,round(m))] > > d = {} > for (l, m) in b: >d[l, roun

Re: efficient intersection of lists with rounding

2004-12-02 Thread Greg Ewing
Gordon Williams wrote: a= [(123,1.3),(123,2.4),(123,7.8),(123,10.2)] b= [(123, 0.9), (123, 1.9), (123, 8.0)] [ (i,round(j)) for i,j in a for l,m in b if (i,round(j)) == (l,round(m))] d = {} for (l, m) in b: d[l, round(m)] = 1 result = [] for (i, j) in a: t = (i, round(j)) if t in d: resul

Re: efficient intersection of lists with rounding

2004-12-02 Thread Michael Hoffman
Steven Bethard wrote: Well, in Python 2.3, I believe sets are implemented in Python while they're implemented in C in Python 2.4. I think the Python 2.3 Sets implementation is likely to be quicker than whatever list-manipulation answer you come up with instead. But there's only one way to find o

Re: efficient intersection of lists with rounding

2004-12-02 Thread Steven Bethard
Gordon Williams wrote: I have to lists that I need to find the common numbers (2nd rounded to nearest integral) and I am wondering if there is a more efficient way of doing it. a= [(123,1.3),(123,2.4),(123,7.8),(123,10.2)] b= [(123, 0.9), (123, 1.9), (123, 8.0)] [ (i,round(j)) for i,j in a for l,m

Re: efficient intersection of lists with rounding

2004-12-02 Thread Diez B. Roggisch
> A couple of other bits of info. > - a and b are ordered smallest to largest (could bisect module be used?) > - in the future I will want to round the second number of closest 0.25 > rather than whole number. > > Would the sets module be more efficient? > > I'm using python 2.3. I'd go for some

efficient intersection of lists with rounding

2004-12-02 Thread Gordon Williams
Hi, I have to lists that I need to find the common numbers (2nd rounded to nearest integral) and I am wondering if there is a more efficient way of doing it. >>> a= [(123,1.3),(123,2.4),(123,7.8),(123,10.2)] >>> b= [(123, 0.9), (123, 1.9), (123, 8.0)] >>> [ (i,round(j)) for i,j in a for l,m in b