Dictionary attributes and functions
Carel Fellinger
cfelling at iae.nl
Fri Mar 9 17:44:00 EST 2001
iddwb <iddwb at imap1.asu.edu> wrote:
...
> attributes that can be reference regarding dictionaries... specifically if
> key(a) is already in dictionsary x I'd like to know prior to
> adding. rather than change the value of key(a) I'd like to add the value
> of key(`a) to the value of key(a) so I end up with
> {keya: [123]}
> on insert of keya againg have something like
> {keya: [123, 234]}
in python 2.0 (or was this already in 1.6?) and newer:
d = dict.setdefault(key, [])
d.append(value)
in older versions still around:
if dict.has_key(key):
dict[key].append(value)
else:
dict[key] = [value]
--
groetjes, carel
More information about the Python-list
mailing list