RE: Way for see if dict has a key
- From: "Cihal Josef" <josef.cihal@xxxxxxxxxxx>
- Date: Fri, 30 Jun 2006 15:22:23 +0200
If dict.has_key('key'):
print dict['']
Josef Cihal
-----Original Message-----
From: python-list-bounces+josef.cihal=sat-automation.com@xxxxxxxxxx
[mailto:python-list-bounces+josef.cihal=sat-automation.com@xxxxxxxxxx]
On Behalf Of Georg Brandl
Sent: Friday, June 30, 2006 5:07 PM
To: python-list@xxxxxxxxxx
Subject: Re: Way for see if dict has a key
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
--
http://mail.python.org/mailman/listinfo/python-list
.
- Prev by Date: Re: list comprehension
- Next by Date: Re[2]: delete first line in a file
- Previous by thread: Re: Way for see if dict has a key
- Next by thread: image output in matplotlib
- Index(es):
Relevant Pages
|