how to append a value to a key in a dictionary in python code example Example: add values to dictionary key python key = "somekey" a.setdefault(key, []) a[key].append(2)