On Sun, Aug 24, 2008 at 8:23 AM, Dan Eloff <[EMAIL PROTECTED]> wrote:
>
> A common python optimization is to replace:
>
> if key in dict:
>    dict[key]
>
> with
>
> try:
>   dict[key]
> except KeyError:
>   pass
>
> The reasoning is that the try/except method is faster if no exception
> is thrown, i.e. you expect the key to be in the dict most of the time.

It's always irritated me that Python dictionaries don't have the
equivalent of TryGetValue.
--
Curt Hagenlocher
[EMAIL PROTECTED]
_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to