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)] b= [(123,

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 if

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:

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, round(m)] = 1 result =