Removing objects

Peter Otten __peter__ at web.de
Wed Jan 23 08:09:38 EST 2008


bladedpenguin wrote:

> So, in general, is it more efficient to use a dictionary or to override
> the __eq__ function?

Rule of thumb: If you want to add/remove arbitrary objects from a
collection a dictionary (or set) is always faster than a list. 

You may still have to override the __eq__() and __hash__() methods whenever
you have distinct objects that can be equal. Caveat: don't use dictionaries
if the result of

obj1 == obj2 # items in the dict

can change during the lifetime of the collection.

Peter



More information about the Python-list mailing list