Re: Way for see if dict has a key



André wrote:
Michele Petrazzo wrote:
Bruno Desthuilliers wrote:
but what the better
Depends on the context.

If know only one context: see if the key are into the dict... What other
context do you know?

Michele

Perhaps Bruno meant this:

try:
... my_dict[key] ...
except:
....


Yes I see :)

when we expect that the key will most often be in my_dict so that
exception will be raised rarely

I didn't thought this because if I think that a key aren't in a dict, I
use dict.get(key, default)


otherwise use if key in dict

André


Thanks to all,
Michele
.