I'm attempting to append these two arrays as they're built but am getting unexpected results in Python:
This = []
That = []
This.append('A')
That.append(This)
This.append('B')
That.append(This)
print(That)
Expected results: [['A'],['A','B']]
Actual results: [['A','B'],['A','B']]
Whereas this works as expected:
That = []
This = ['A']
That.append(This)
This2 = ['A', 'B']
That.append(This2)
print(That)
Expected results: [['A'],['A','B']]
Actual results: [['A'],['A','B']]
You have to think of the "this" as just one object, if you want 2 different objects in you have to copy a copy of this like
That.append(This.copy())https://docs.python.org/3/library/copy.html