# I would like to ask you about the Python sequence list element modification.

Asked 2 weeks ago, Updated 2 weeks ago, 1 views

We're working on a simple code that represents the DNA sequence in Python.

Code that stores the base sequence in the list when it is entered, transforms the list element according to the rule with a for statement and an if statement, and outputs the changed list. (Rule: A --> T, T --> A)

But if I did it like I planned it, the for statement was executed, and I changed only a and I didn't touch a and a.

So even if I input ATA, the if statement is applied only to a and ['T', 'T', 'A'] is printed out like this. (If it is printed correctly according to the rule, it should be printed as ['T', 'A', 'T']) How do you apply the if statement to a, a and output it correctly according to the rule?

``````DNA_list = list (map(str, input("Enter 3 base sequence").split()))
a = DNA_list

for i in a:
if (i == "A") :
a[a.index("A")] = "T"

elif (i == "T") :
a[a.index("T")] = "A"

else :
a = "You entered the wrong sequence"

print(a)

``````

python list

2022-09-20 11:34

a.Index ("A") always tells you the first index. So only the first one will change. There are other problems with the code, but it is.

All you have to do is take the mapping rules that you want to convert and map them one by one. Let's write list compliance.

``````Mapping rule = {"A":"T", "T":"A"}

seq = [mapping rule [ele] for ele in seq]

``````

You can roughly do it like this.

2022-09-20 11:34

## If you have any answers or tips

Popular Tags
python x 4519
android x 1589
java x 1455
javascript x 1363
c x 881
php x 682
html x 629
swift x 586
ios x 538
mysql x 397