Pythonic way for missing dict keys

Alex Popescu nospam.themindstorm at
Sat Jul 28 13:52:48 CEST 2007

jjl at (John J. Lee) wrote in news:87lkd0eprj.fsf at

> Alex Popescu <nospam.themindstorm at> writes:
>> Zentrader <zentraders at> wrote in
>> news:1185041243.323915.161230
>>> On Jul 21, 7:48 am, Duncan Booth < at invalid.invalid>
>>> wrote: 
>>> [snip...]
>>>>From the 2.6 PEP #361 (looks like dict.has_key is deprecated)
>>> Python 3.0 compatability: ['compatibility'-->someone should use a
>>> spell-checker for 'official' releases]
>>>         - warnings were added for the following builtins which no
>>> longer exist in 3.0:
>>>              apply, callable, coerce, dict.has_key, execfile,
>>>              reduce, 
>>> reload
>> I see... what that document doesn't describe is the alternatives to
>> be used. And I see in that list a couple of functions that are
>> probably used a lot nowadays (callable, reduce, etc.).
> callable and reduce are rarely used, at least in code I've seen.  

I thought G would be using that function a lot. Also, what is the 
replacement of reduce? I think I remember seeing somewhere that lists 
comprehension would be (but also remember the advise that reduce will be 

> Certainly has_key will be
> the most common of those listed above (but trivial to fix).  

dict.has_key(key) becomes key in dict (correct?)

> apply
> will be common in old code from the time of Python 1.5.2.  

I think there were some advises to not use apply.

> execfile is
> perhaps more common that callable (?) but again is really a "maybe 1
> call in a big program" sort of thing.  

What is the replacement for this one? 

.w( the_mindstorm )p.

More information about the Python-list mailing list