Building and Transvering multi-level dictionaries

Nathan Clegg nathan at islanddata.com
Tue Mar 21 03:04:30 CET 2000


On 21-Mar-2000 Eric Hagemann wrote:
>#add a key and setup for a sub-dictionary
> if(D.has_key('a') == 0)
>     D['a'] = {}


In my opinion, this is a very dangerous habit to get into.  Unlike C,
perl and python have more than one false value.  I don't know that
you can be sure that a built-in such as this is guaranteed to be
consistent between versions of python.  Even more dangerous is that
modules and functions written by others could use any of the false
values.  I personally always return None for false.  Seems to me much
safer to do:

if not D.has_key('a'):
        D['a'] = {}


----------------------------------
Nathan Clegg
 nathan at islanddata.com






More information about the Python-list mailing list