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

Michael Foord fuzzyman at voidspace.org.uk
Mon Aug 25 09:04:17 PDT 2008


Curt Hagenlocher wrote:
> 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.
>   

Like the 'get' method?

Michael

> --
> Curt Hagenlocher
> curt at hagenlocher.org
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>   


-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/
http://www.trypython.org/
http://www.ironpython.info/
http://www.theotherdelia.co.uk/
http://www.resolverhacks.net/



More information about the Users mailing list