Slow comparison between two lists
Bruno Desthuilliers
bruno.42.desthuilliers at websiteburo.invalid
Thu Oct 23 08:33:38 EDT 2008
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 30000 addresses.
>
> I've defined __eq__ method in my class like this:
>
> def __eq__(self, other):
> return self.xcoord == other.xcoord and \
> self.ycoord == other.ycoord and \
> self.streetname == other.streetname and \
> self.streetno == other.streetno
>
> But it turns out to be very, very slow.
>
> Then I setup two lists:
>
> list_external = getexternal()
> list_internal = getinternal()
>
> Now I need get all all addresses from 'list_external' that are not in
> 'list_internal', and mark them as "new".
>
> I did it like this:
>
> 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?
mmm... not using sets ?
More information about the Python-list
mailing list