python dictionary append value if key exists code example
Example 1: append to list in dictionary python if exists
dic.setdefault(key,[]).append(value)
Example 2: python dictionary append value if key exists
from collections import defaultdict
d = defaultdict(list)
d['key'].append('mykey')