I have a string that I want to manipulate at every position throughout it's length.
For example, I have a string that looks something like this:
string1 = 'AATGCATT'
I want to create a list where I change one position at a time to either an A, T, C, or G. I was thinking of using an approach as so:
liststring = list(string1)
changedstrings = []
for pos in range(2, len(liststring) - 2): ##I don't want to change the first and last to characters of the string
if liststring[pos] != 'A':
liststring[pos] = 'A'
random1 = "".join(liststring)
changedstrings.append(random1)
I was thinking of using the similar approach to append the rest of the changes (changing the rest of the positions to G,C, and T) to the list generated above. However, when I print the changedstrings
list, it appears the this code changes all of the positions to A after the first two. I really just wanted to change position 3 to 'A' and append to list. Then change position 4 to 'A' and append to list and so on to give me a list as so:
changedstrings = ['AAAGCATT', 'AATACATT', 'AATGAATT']
Any suggestions?