You have many answers to your problem but none address your issue, so looking at your code and hopefully this can help:
seq
is a string and as such is immutable in python, so:
seq[i] = 'T'
is not valid python. You already created a list1
so did you mean:
list1[i] = 'T'
Note, this still wouldn't work because i
is not the index but a character in seq
but you can get both the index and character with enumerate()
, e.g.:
for i, c in enumerate(seq):
if c == 'A':
list1[i] = 'T'
...
In python str.translate()
is ideal for translating multiple characters, e.g. for your simple example:
def dna():
t = str.maketrans('A', 'T')
seq = input('Enter the sequence: ')
return seq.translate(t)
And this is easy to extend, e.g. A->T
and G->C
and vice versa would look like:
t = str.maketrans('AGTC', 'TCAG')