lists and append, and loop iteration

Janko Hauser jhauser at ifm.uni-kiel.de
Wed Sep 22 05:55:30 EDT 1999


Charles G Waldman <cgw at fnal.gov> writes:

> I would write 
> 
>  dict['new_key'] = dict.get('new_key',[]) + [new_value]
> 
This is a trick, because it does only supress the exception. But has
the same effect :-)

I could not write
>>> dict={}
>>> dict['new_key'] = dict.get('new_key',[]).append(['new_value'])
>>> dict
{'new_key': None}

To this refered my last note about the reference of a. Although I do
not understand this. If I get not an empty list, why can I do an
append?

Questioned,

__Janko



-- 
  Institut fuer Meereskunde             phone: 49-431-597 3989
  Dept. Theoretical Oceanography        fax  : 49-431-565876
  Duesternbrooker Weg 20                email: jhauser at ifm.uni-kiel.de
  24105 Kiel, Germany




More information about the Python-list mailing list