- I have following dictionary:
original = {a:1, b:2} - I then run dict comprehension:
extracted = {k:v for (k,v) in original.items() if k == 'a'} - The following dict is returned:
{a:1} - If I mutate
extracted['a'] = 2,original['a']will still be equal to1
Question:
Is there a way to make the above dict comprehension return by reference? For example extracted['a'] = 2 would result in original['a'] = 2.
I would prefer not to involve alteration of the original dictionary.