Re: Way for see if dict has a key
- From: "Fredrik Lundh" <fredrik@xxxxxxxxxxxxxx>
- Date: Fri, 30 Jun 2006 13:34:37 +0200
"André" wrote:
Perhaps Bruno meant this:
try:
... my_dict[key] ...
except:
...
when we expect that the key will most often be in my_dict so that
exception will be raised rarely, otherwise use
on my machine, "key in dict" is about twice as fast as the full try/getitem con-
struct when the key is present in the dict, so that's not a very good optimization.
now, if the OP had been interested in the associated value, things might have
been a bit different.
</F>
.
- Follow-Ups:
- Re: Way for see if dict has a key
- From: Bruno Desthuilliers
- Re: Way for see if dict has a key
- References:
- Way for see if dict has a key
- From: Michele Petrazzo
- Re: Way for see if dict has a key
- From: Bruno Desthuilliers
- Re: Way for see if dict has a key
- From: Michele Petrazzo
- Re: Way for see if dict has a key
- From: André
- Way for see if dict has a key
- Prev by Date: Re: Way for see if dict has a key
- Next by Date: Re: Way for see if dict has a key
- Previous by thread: Re: Way for see if dict has a key
- Next by thread: Re: Way for see if dict has a key
- Index(es):
Relevant Pages
|