I need to write a function that takes a string only containing 'A'
or 'C'
or 'G'
or 'T'
and change these string according to my codes, otherwise it will return ''
. I wrote these codes and my codes seems works fine, but whenever my function receives unsupported character it returns nothing when it is supposed to return ''
.
def dna2rna(s):
rna = []
# if s.isupper() == False: #or [charr for charr in s if s != 'A' or 'C' or 'G' or 'T']:
#return ''
#else
if [char for char in s]:
for char in s:
if char == 'A' or 'C' or 'G' or 'T' or ' ':
if char == 'A':
rna.append('U')
elif char == 'C':
rna.append('G')
elif char == 'G':
rna.append('C')
elif char == 'T':
rna.append('A')
print ''.join(rna)
else:
return ''
print dna2rna('cs5')