I have a collection of arrays which "overlap" at certain elements. Here's a picture of an example involving 3 arrays of characters:
array0↓
'A' ↓array2
array1→'B' 'D' 'E'
'C' 'F'
The important thing is that changes to the arrays should respect this structure. So for example, if I change the 'B' in array0 to 'X', the 'B' in array1 should also change to 'X'.
My question is what is a good, efficient way of implementing this in Python?
There are two things I have thought of so far:
One, I can make a bespoke class, instances of which contain a completely distinct list, along with information about any overlaps that it has, and implement update methods appropriately so that any change to the list is always duplicated for the other lists at the overlaps. This seems a little overwrought though, and involves duplicating the data.
Two, I could do it by using singleton lists like this:
data = [['A'], ['B'], ['C'], ['D'], ['E'], ['F']]
array0 = [data[0], data[1], data[2]]
array1 = [data[1], data[3], data[4]]
array2 = [data[4], data[5]]
for array in array0, array1, array2:
print(array)
>>> [['A'], ['B'], ['C']]
>>> [['B'], ['D'], ['E']]
>>> [['E'], ['F']]
array0[1][0] = 'X'
for array in array0, array1, array2:
print(array)
>>> [['A'], ['X'], ['C']]
>>> [['X'], ['D'], ['E']]
>>> [['E'], ['F']]
But I feel this may be hacky and not the best way. Thanks for any suggestions.