dictionary total sum

py at blacktoli.com py at blacktoli.com
Wed Sep 7 19:50:08 EDT 2016


Hello,

any ideas why this does not work?

>>> def add(key, num):
...     a[key] += num
...
>>> a={}
>>> a["007-12"] = 22 if not a.has_key("007-12") else add("007-12",22)
>>> a
{'007-12': 22} # OK here, this is what I want
>>> a["007-12"] = 22 if not a.has_key("007-12") else add("007-12",22)
>>> a
{'007-12': None} # why does this became None?

Thanks




More information about the Python-list mailing list