Are there any list comparison optimizations in Python?

Jonathan P. jbperez808 at yahoo.com
Tue Nov 13 01:36:32 CET 2001


>>> x=[1,2,3]
>>> y=x

>>> xlist=[x,1,2,3]
>>> ylist=[y,1,2,3]

>>> xlist==ylist

>>> xlist.remove(x) # these 2 statements not executed one after
>>> xlist.remove(y) # the other but representing different cases
>>> ylist.remove(x)

One of Python's most convenient high-level features is automatic list
comparison by value and recursively.

Does it know to optimize the compare if it has already been determined
that two items share a reference to the same object by not doing a
value compare on them anymore?

And will this apply to both the comparison and remove() calls above?



More information about the Python-list mailing list