I\'m trying to convert the DNA code into RNA code using Python...
I write this:
print(\'Digite a sequência DNA a ser transcrita para RNA:\')
my_str
i, j = "ATGC", "UACG"
tbl = str.maketrans(i, j)
my_str = "GUTC"
print(my_str.translate(tbl))
[out]:
'CUAG'
RNA_compliment
str.maketrans
accepts one argument as a dictionary{ord('A'): 'U', ord('T'): 'A', ord('G'): 'C', ord('C'): 'G'}
ord()
isn't required# dict without ord
RNA_compliment = {'A': 'U', 'T': 'A', 'G': 'C', 'C': 'G'}
tbl2 = i.maketrans(RNA_compliment)
print(my_str.translate(tbl2))
[out]:
'CUAG'
ord
with a dict
for python3, not for python2:In [1]: from string import maketrans
In [2]: i, j = "ATGC", "UACG"
In [3]: tbl = maketrans(i,j)
In [4]: my_str = "GUTC"
In [5]: my_str.translate(tbl)
Out[5]: 'CUAG'