I'm writing some code for a bioinformatics library in Python 3.9.4
def immediate_neighbors(seq):
neighborhood = [seq]
for i, ntide in enumerate(seq):
for other_ntide in ['A', 'C', 'G', 'T']:
if ntide != other_ntide:
neighbor = seq
neighbor[i] = other_ntide
neighborhood.append(neighbor)
print(seq)
return neighborhood
When I input ['C', 'A', 'A']
I get the output
['A', 'A', 'A']
['G', 'A', 'A']
['T', 'A', 'A']
['T', 'C', 'A']
['T', 'G', 'A']
['T', 'T', 'A']
['T', 'T', 'C']
['T', 'T', 'G']
['T', 'T', 'T']
[['T', 'T', 'T'], ['T', 'T', 'T'], ['T', 'T', 'T'], ['T', 'T', 'T'], ['T', 'T', 'T'], ['T', 'T', 'T'], ['T', 'T', 'T'], ['T', 'T', 'T'], ['T', 'T', 'T'], ['T', 'T', 'T']]
The print(seq)
was put there just for debugging purposes. The original variable seq
is clearly being written over, but I can't figure it how this is happening.