Algorithm/문제풀이
exercism RNA-transcription solution
dr.meteor
2020. 1. 24. 19:03
P)
Given a DNA strand, return its RNA complement (per RNA transcription).
Both DNA and RNA strands are a sequence of nucleotides.
The four nucleotides found in DNA are adenine (**A**), cytosine (**C**),
guanine (**G**) and thymine (**T**).
The four nucleotides found in RNA are adenine (**A**), cytosine (**C**),
guanine (**G**) and uracil (**U**).
Given a DNA strand, its transcribed RNA strand is formed by replacing
each nucleotide with its complement:
* `G` -> `C`
* `C` -> `G`
* `T` -> `A`
* `A` -> `U`
sol1)
def to_rna(text):
# get이란 함수가 있는지 몰랐는데, 파라미터로 key 이름 받으면 value를 get한다.
rna = ''.join(map(lambda char: {'G': 'C', 'C': 'G', 'T': 'A', 'A': 'U'}.get(char, ''), text))
return rna if len(rna) == len(text) else ''
sol2)
def to_rna(dna):
dna_to_rna = {'A':'U','T':'A','C':'G','G':'C'}
return ''.join(dna_to_rna[i] for i in dna)