I have two lists of integers that I plan to modify repeatedly. I'd like to be able to retrieve these from a single object, indexing the lists with -1 and 1 respectively. I tried creating two lists and storing them in a dictionary with keys -1 and 1, but after assigning to one of the lists, changes are not reflected in the dictionary.
foo = [1,2,3]
bar = [4,5,6]
mydict = {-1:foo,1:bar}
foo.append(0)
foo = [2,3,4]
mydict[-1] # this is [1,2,3,0], but I'd like it to be [2,3,4]
I realize I could just assign to mydict[-1] directly, but I am concerned that this would be inefficient given that a python dict is a hash table, and foo and bar will change size repeatedly (possibly requiring re-hashing -- ??).
Is there a Pythonic way to do this?