Re: Way for see if dict has a key
- From: Georg Brandl <g.brandl-nospam@xxxxxxx>
- Date: Fri, 30 Jun 2006 17:06:38 +0200
Bruno Desthuilliers wrote:
looping 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?
Why do you want to do that ?
if key in dict:
value = dict[key]
else:
value = None
could be write:
value = dict.get(key, None)
value = dict.get(key)
;)
Georg
.
- 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: looping
- Re: Way for see if dict has a key
- From: Bruno Desthuilliers
- 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):