Re: Slow comparison between two lists

2008-10-23 Thread Steven D'Aprano
On Thu, 23 Oct 2008 05:03:26 -0700, Jani Tiainen wrote: > But in my case running that loop takes about 10 minutes. What I am doing > wrong? Others have already suggested you have a O(N**2) algorithm. Here's an excellent article that explains more about them: http://www.joelonsoftware.com/articl

Re: Slow comparison between two lists

2008-10-23 Thread bearophileHUGS
Hrvoje Niksic: > You're right.  The OP states he implements __eq__, so he also needs a > matching __hash__, such as: > >     def __hash__(self, other): >         return (hash(self.xcoord) ^ hash(self.ycoord) ^ >                 hash(self.streetname) ^ hash(self.streetno)) The hash function by Otte

Re: Slow comparison between two lists

2008-10-23 Thread Hrvoje Niksic
[EMAIL PROTECTED] writes: >> internal = set(list_internal) > ... > > To do that the original poster may have to define a __hash__ and > __eq__ methods in his/her class. You're right. The OP states he implements __eq__, so he also needs a matching __hash__, such as: def __hash__(self, other)

Re: Slow comparison between two lists

2008-10-23 Thread Jani Tiainen
On 23 loka, 15:24, Peter Otten <[EMAIL PROTECTED]> wrote: > Jani Tiainen wrote: > > I have rather simple 'Address' object that contains streetname, > > number, my own status and x,y coordinates for it. I have two lists > > both containing approximately 3 addresses. > > > I've defined __eq__ met

Re: Slow comparison between two lists

2008-10-23 Thread Bruno Desthuilliers
Jani Tiainen a écrit : I have rather simple 'Address' object that contains streetname, number, my own status and x,y coordinates for it. I have two lists both containing approximately 3 addresses. I've defined __eq__ method in my class like this: def __eq__(self, other): return

Re: Slow comparison between two lists

2008-10-23 Thread Stef Mientki
On Thu, Oct 23, 2008 at 2:03 PM, Jani Tiainen <[EMAIL PROTECTED]> wrote: > I have rather simple 'Address' object that contains streetname, > number, my own status and x,y coordinates for it. I have two lists > both containing approximately 3 addresses. > > I've defined __eq__ method in my clas

Re: Slow comparison between two lists

2008-10-23 Thread bearophileHUGS
Hrvoje Niksic: > internal = set(list_internal) ... To do that the original poster may have to define a __hash__ and __eq__ methods in his/her class. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Slow comparison between two lists

2008-10-23 Thread Peter Otten
Jani Tiainen wrote: > I have rather simple 'Address' object that contains streetname, > number, my own status and x,y coordinates for it. I have two lists > both containing approximately 3 addresses. > > I've defined __eq__ method in my class like this: > > def __eq__(self, other): >

Re: Slow comparison between two lists

2008-10-23 Thread Hrvoje Niksic
Jani Tiainen <[EMAIL PROTECTED]> writes: > for addr in list_external: > if addr not in list_internal: > addr.status = 1 # New address > > But in my case running that loop takes about 10 minutes. What I am > doing wrong? The nested loop takes time proportional to the product of the num