Files
exercism_puzzles/python/protein-translation/protein_translation.py
T

32 lines
724 B
Python

codon_to_protein: dict[str, str] = {
"AUG": "Methionine",
"UUU": "Phenylalanine",
"UUC": "Phenylalanine",
"UUA": "Leucine",
"UUG": "Leucine",
"UCU": "Serine",
"UCC": "Serine",
"UCA": "Serine",
"UCG": "Serine",
"UAU": "Tyrosine",
"UAC": "Tyrosine",
"UGU": "Cysteine",
"UGC": "Cysteine",
"UGG": "Tryptophan",
}
stop_codons: list[str] = ["UAA", "UAG", "UGA"]
def proteins(strand):
protein: list[str] = []
codon: str = ""
for nucleotide in strand:
codon += nucleotide
if len(codon) == 3:
if codon in stop_codons:
break
protein.append(codon_to_protein[codon])
codon = ""
return protein