When I want to append a newvalue into Dict under Key, I find myself have to write:
# Dict={}
# Key = ....
# newvalue = ....
if not Key in Dict:
Dict[Key] = [ newvalue ]
else:
Dict[Key].append(newvalue)
It costs four lines of code. Is there a more concise way with python standard library? e.g
Dict.appendkeyvalue(Key, newvalue)
You can use a
defaultdict: