-
Notifications
You must be signed in to change notification settings - Fork 0
/
complementary-DNA.py
27 lines (24 loc) · 1.17 KB
/
complementary-DNA.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""
Solution to the CodeWars kata Complementary DNA
Link:
https://www.codewars.com/kata/554e4a2f232cdd87d9000038
"""
def DNA_strand(dna):
#In DNA strings, symbols "A" and "T" are complements of each other, as "C" and "G". You have function with one side of the DNA (string, except for Haskell); you need to get the other complementary side. DNA strand is never empty or there is no DNA at all
dna_answer=""
for item in dna:
if item == "A":
dna_answer+="T"
elif item == "T":
dna_answer+="A"
elif item == "C":
dna_answer+="G"
else:
dna_answer+="C"
return dna_answer
# -----------------------------------------------------Extras-----------------------------------------------------
#Other solution
def DNA_strand2(dna):
#In DNA strings, symbols "A" and "T" are complements of each other, as "C" and "G". You have function with one side of the DNA (string, except for Haskell); you need to get the other complementary side. DNA strand is never empty or there is no DNA at all
pairs = {'A':'T','T':'A','C':'G','G':'C'}
return ''.join([pairs[x] for x in dna])