Python字符串的替换

1.用字典存对应的替换规则,用循环取键值对应:

dict1 = {'A':'U','U':'A','C':'G','G':'C'}  
def mRNA_tRNA(s):  
    list1 = []  
    for ent in range(0,len(s)):  
        list1.append(dict1[s[ent]])  
    return ''.join(list1)  

2..replace()
a='CGAU'
>>> B=a.replace('C','P')
>>> B
'PGAU'

猜你喜欢

转载自blog.csdn.net/tommy1295/article/details/80556335