[IronPython] Performance of IronPython 2 Beta 4 and IronPython 1

Curt Hagenlocher curt at hagenlocher.org
Mon Aug 25 18:02:41 CEST 2008


On Sun, Aug 24, 2008 at 8:23 AM, Dan Eloff <dan.eloff at gmail.com> 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
curt at hagenlocher.org



More information about the Ironpython-users mailing list