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

Like the 'get' method?

Michael

--
Curt Hagenlocher
[EMAIL PROTECTED]
_______________________________________________
Users mailing list
Users@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/

_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to