I want to append value to an existing dictionary. Here is my code:
tmp_result = [{'M': 8}, {'N': 16},]
cross_configs = [({'device': 'cpu'},), ({'device': 'cuda'},)]
import copy
generated_configs = []
for config in cross_configs:
for value in config:
new_value = copy.deepcopy(tmp_result)
new_value.append(value)
generated_configs.append(new_value)
print (generated_configs)
Output:
[[{'M': 8}, {'N': 16}, {'device': 'cpu'}], [{'M': 8}, {'N': 16}, {'device': 'cuda'}]]
I don't like the inner loop which does deepcopy and append. What is a pythonic way to do that?