관리 메뉴

A seeker after truth

exercism RNA-transcription solution 본문

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)

'Algorithm > 문제풀이' 카테고리의 다른 글

프로그래머스 정렬 문제(2) (작성중)  (0) 2020.01.25
exercism raindrops solution  (0) 2020.01.24
exercism pangram solution  (0) 2020.01.24
exercism leap solution  (0) 2020.01.24
exercism reverse-string solution  (0) 2020.01.24