> 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
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
"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)]
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
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
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
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
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
> 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
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
10 matches
Mail list logo