How to add pairs to a dict, typo corrected in this one.

Paul Rubin http
Fri Mar 12 11:01:02 CET 2004

Avik Ghose <avikghose at> writes:
> if 'tom' in phone_book.keys():
>     #duplicate entry;

Don't do it that way!  That builds up a whole list from scratch containing
all the keys, and then searches the list for 'tom'!!!  There was just
a thread about this :).

Instead, use: 

   if 'tom' in phone_book: ...


   if phone_book.has_key('tom'): ...

More information about the Python-list mailing list