[Tutor] Performance difference, ``in'' vs ``has_key()''
bill at celestial.net
Sun Jul 17 20:18:03 CEST 2005
I'm going to be doing some work where I'll be doing existence
testings on keys on about a million records where it may require
multiple passes so I'm a bit concerned about the timing of these
Is there any significant performance difference between the
tests, ``key in dictionary'' and ``dictionary.has_key(key)''?
I would prefer using the ``key in'' because it's a bit easier to
type, and can also be used with lists in addition to dictionaries.
A related question is where's the trade-off between using ``in''
with a list, and a dictionary? I presume that using it with
small hashes will be faster than dictionries since it doesn't
have to calculate the hashes.
INTERNET: bill at Celestial.COM Bill Campbell; Celestial Software LLC
UUCP: camco!bill PO Box 820; 6641 E. Mercer Way
FAX: (206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676
Government is the great fiction, through which everbody endeavors to
live at the expense of everybody else. -- Frederic Bastiat
More information about the Tutor