'Alias for long list name and modification
I have a nested data structure (e.g. mydict[names[num]]) which is difficult to read in code. Hence I would like to create a proxy (alias) and use it to modify this structure.
long_name = [1,2,3]
short = long_name
assert id(long_name) == id(short)
short.append(4)
assert id(long_name) == id(short)
short = [n**2 for n in short]
assert id(long_name) == id(short) # AssertionError
Given the AssertionError on id(a) = id(b), do I understand correctly python separates short and long_name during comprehension and allocates separate memory?
In practice, my structure contains millions of long strings, so takes up a lot of space (memory), hence this concern.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
