Re: If Dict Contains a particular key

2007-04-26 Thread Alex Martelli
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: ... > > > > if 'a' in thedict: ... > > > if thedict.has_key('a'): ... > > Why consume twice as much time with no advantages whatever?! > > Did I wander into comp.lang.perl by mistake? Of course not -- note that the faster, modern idiom is

Re: If Dict Contains a particular key

2007-04-26 Thread [EMAIL PROTECTED]
On Apr 26, 12:47 am, [EMAIL PROTECTED] (Alex Martelli) wrote: > [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > >... > > > > if 'a' in thedict: > > > ... > > > > There's no need for the call to keys(). > > > Why not > > > if thedict.has_key('a'): > > pass > > elde: > > pass

Re: If Dict Contains a particular key

2007-04-26 Thread Alex Martelli
John Nagle <[EMAIL PROTECTED]> wrote: ... > It would be useful if there was some direct way to get the value > associated with a key, and None if there's not one. >From : """ Guido's most important attribute besides Python itself is Guido's tim

Re: If Dict Contains a particular key

2007-04-26 Thread Steve Holden
Gabriel Genellina wrote: > En Thu, 26 Apr 2007 03:56:17 -0300, John Nagle <[EMAIL PROTECTED]> > escribió: > >> On Tue, 2007-04-24 at 18:28 +0100, Robert Rawlins - Think Blue wrote: >>> I'm Looking to build a quick if/else statement that checks a >>> dictionary for a key like follows.

Re: If Dict Contains a particular key

2007-04-26 Thread Gabriel Genellina
En Thu, 26 Apr 2007 03:56:17 -0300, John Nagle <[EMAIL PROTECTED]> escribió: > On Tue, 2007-04-24 at 18:28 +0100, Robert Rawlins - Think Blue wrote: >> I'm Looking to build a quick if/else statement that checks a >> dictionary for a key like follows. > > It would be useful if th

Re: If Dict Contains a particular key

2007-04-26 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote: > On Apr 24, 1:41 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: >> Steven Howe wrote: >> >> > or try: >> > thedict = { 'a': 1, 'b':2, 'c':3 } >> > if 'a' in thedict.keys(): >> >print thedict['a'] >> >> Better yet, just: >> >> if 'a' in thed

Re: If Dict Contains a particular key

2007-04-25 Thread John Nagle
[EMAIL PROTECTED] wrote: > On Apr 24, 1:41 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: > >>Steven Howe wrote: >> >>>Carsten Haese wrote: >>> On Tue, 2007-04-24 at 18:28 +0100, Robert Rawlins - Think Blue wrote: >> >Hello Guys, >> >I'm Looking to build a quick if/else statement that c

Re: If Dict Contains a particular key

2007-04-25 Thread Alex Martelli
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: ... > > if 'a' in thedict: > > ... > > > > There's no need for the call to keys(). > > Why not > > if thedict.has_key('a'): > pass > elde: > pass has_key exists only for backwards compatibility; the 'in' operator is preferable

Re: If Dict Contains a particular key

2007-04-25 Thread [EMAIL PROTECTED]
On Apr 24, 1:41 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: > Steven Howe wrote: > > Carsten Haese wrote: > >> On Tue, 2007-04-24 at 18:28 +0100, Robert Rawlins - Think Blue wrote: > > >>> Hello Guys, > > >>> I'm Looking to build a quick if/else statement that checks a > >>> dictionary for a key

RE: If Dict Contains a particular key

2007-04-25 Thread Robert Rawlins - Think Blue
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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Michael Bentley Sent: 24 April 2007 18:37 To: python-list@python.org Subject: Re: If Dict Contains

Re: If Dict Contains a particular key

2007-04-24 Thread Steven Bethard
Steven Howe wrote: > Carsten Haese wrote: >> On Tue, 2007-04-24 at 18:28 +0100, 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:

Re: If Dict Contains a particular key

2007-04-24 Thread Steven Howe
Carsten Haese wrote: > On Tue, 2007-04-24 at 18:28 +0100, 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..

Re: If Dict Contains a particular key

2007-04-24 Thread Carsten Haese
On Tue, 2007-04-24 at 18:28 +0100, 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

Re: If Dict Contains a particular key

2007-04-24 Thread Michael Bentley
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 o

If Dict Contains a particular key

2007-04-24 Thread Robert Rawlins - Think Blue
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? Thanks, Rob -- http://mail.python.org/mailman