NEWBIE QUESTIION: Comparing Lists in Python

Mike Brenner mikeb at mitre.org
Thu May 2 16:02:35 EDT 2002


In determining to compare two lists (for list_minus, list_intersect, or whatever), the question arise whether to look up the shorter list in a dictionary constructed from the long list or to look up the longer list in a dictionary constructed from the shorter list.

As the list gets longer (hundreds of thousands or millions), the latter starts becoming much faster, so a general utility should construct the dictionary from the shorter list and look up the longer list in it. I assume that the time to construct a dictionary is non-linear.






More information about the Python-list mailing list