mirror of
https://github.com/Xevion/exercism.git
synced 2025-12-08 14:07:01 -06:00
'init'
This commit is contained in:
19
python/protein-translation/protein_translation.py
Normal file
19
python/protein-translation/protein_translation.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from itertools import takewhile
|
||||
|
||||
# Processing of data into a dictionary from a list taken from the site.
|
||||
# I would have preferred being able to process the data from a module, or maybe a text file,
|
||||
# but that's a whole lot of effort for something as simple as this.
|
||||
data = [['AUG', 'Methionine'],
|
||||
['UUU', 'UUC', 'Phenylalanine'],
|
||||
['UUA', 'UUG', 'Leucine'],
|
||||
['UCU', 'UCC', 'UCA', 'UCG', 'Serine'],
|
||||
['UAU', 'UAC', 'Tyrosine'],
|
||||
['UGU', 'UGC', 'Cysteine'],
|
||||
['UGG', 'Tryptophan'],
|
||||
['UAA', 'UAG', 'UGA', 'STOP']]
|
||||
protein_definitions = {codon : definition for definition, codons in [(subarray[-1], subarray[:-1]) for subarray in data] for codon in codons }
|
||||
|
||||
def proteins(strand):
|
||||
strand = [strand[index * 3:(index * 3)+3] for index, char in enumerate(strand[::3])]
|
||||
strand = takewhile(lambda x : x != 'STOP', (protein_definitions[codon] for codon in strand))
|
||||
return list(strand)
|
||||
Reference in New Issue
Block a user