Python doesn't support pointers like C/C++ does, but you could use lists to serve as references. To access the value, you'd index into the first element of the list.
data = {
'key1': ['value1']
}
data['key3'] = data['key1'] # copy the list by reference
print(f"Old: {data['key3'][0]}, {data['key3'][0] == data['key1'][0]}")
data['key1'][0] = 'new-value' # this will modify the value from data['key3'] as well
print(f"New: {data['key3'][0]}, {data['key3'][0] == data['key1'][0]}")
Output:
Old: value1, True
New: new-value, True
Note that, this assumes that you're fully aware of which values act as "pointers" and which ones don't.
For example,
data = {
'key1': ['pointer-list'], # should act as a "pointer"
'key2': ['normal', 'list'] # should act as a normal list
}
data['key3'] = data['key1'] # copy list by reference
data['key1'][0] = 'new-value' # propogate new value to other references
data['key4'] = data['key2'] # oops – copy list by reference
data['key2'][0] = 'new-value' # oops – data['key2'] should act as a normal list but
# the new value is propogated to data['key4'] as well
To deal with this issue, clone or copy the list instead.
import copy
data['key4'] = copy.copy(data['key2'])
# data['key4'] = copy.deepcopy(data['key2']) # if the value contains nested lists
# data['key4'] = data['key2'].copy() # another way