Are there any list comparison optimizations in Python?
Peter Hansen
peter at engcorp.com
Mon Nov 12 21:40:59 EST 2001
"Jonathan P." wrote:
>
> 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?
I just created two million-integer lists with "[0] * 1000000" and
compared them, then reassigned the second name to reference the
first list and compared again. There was a noticeable pause during
both compares (with "==").
Comparing two lists with different lengths *does* return
"immediately".
-empirically-yr's
--
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com
More information about the Python-list
mailing list