try vs. has_key()

Darrell news at dorb.com
Thu Apr 22 20:16:51 EDT 1999


My experience shows that throwing an exception is slower.

Aahz Maruch <aahz at netcom.com> wrote in message
news:aahzFAM4oJ.M7M at netcom.com...
> I've seen roughly half the people here doing
>
> try:
>    dict[key].append(foo)
> except:
>    dict[key]=[foo]
>
> with the other half doing
>
> if dict.has_key(key):
>    dict[key].append(foo)
> else:
>    dict[key]=[foo]
>
> Can people explain their preferences?
> --
>                       --- Aahz (@netcom.com)
>
> Hugs and backrubs -- I break Rule 6       <*>
http://www.rahul.net/aahz/
> Androgynous poly kinky vanilla queer het
>
> "You often don't really understand the problem until after the first
> time you implement a solution."  - Eric S. Raymond






More information about the Python-list mailing list