tag:blogger.com,1999:blog-3531969847869413627.post3555968110346677120..comments2023-07-05T07:05:39.753-04:00Comments on Boduch's Blog: Python Key ErrorsAdam Boduchhttp://www.blogger.com/profile/00484502507931628726noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-3531969847869413627.post-88330967500155190312010-03-13T17:14:18.163-05:002010-03-13T17:14:18.163-05:00You may want to look into the "get" meth...You may want to look into the "get" method for dictionaries. It does a lookup for a key in a dictionary and if it does not exist it will return a default value if one is provided. In the above example you would do dictobj.get('b',None) and in the case where b is not in the dictionary it would result None to you. Syntax-wise it is a lot nicer and running your benchmark is only slightly slower then the has_key method (in my test it was 2.0 sec vs 1.8 sec).Jonathan Kupfermanhttps://www.blogger.com/profile/11372052464032359994noreply@blogger.com