If Dict Contains a particular key

Robert Rawlins - Think Blue robert.rawlins at thinkbluemedia.co.uk
Wed Apr 25 09:04:36 CEST 2007


Thanks guys for this, glad it was so simple.

 

I used mikes solution in the end, and it worked a charm.

 

Thanks again,

 

Rob

 

From: python-list-bounces+robert.rawlins=thinkbluemedia.co.uk at python.org
[mailto:python-list-bounces+robert.rawlins=thinkbluemedia.co.uk at python.org]
On Behalf Of Michael Bentley
Sent: 24 April 2007 18:37
To: python-list at python.org
Subject: Re: If Dict Contains a particular key

 

 

On Apr 24, 2007, at 12:28 PM, Robert Rawlins - Think Blue wrote:





Hello Guys,

 

I'm Looking to build a quick if/else statement that checks a dictionary for
a key like follows.

 

If myDict contains ThisKey:

                Do this...

Else

                Do that...

 

Thats the best way of doing this?

if ThisKey in myDict:

  pass # do this

else:

  pass # do that

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070425/d0632671/attachment.html>


More information about the Python-list mailing list