translate maketrans

Транскрипція РНК
Транскрипція РНК у треку Python
LOOKUP = str.maketrans('GCTA', 'CGAU')


def to_rna(dna_strand):
    return dna_strand.translate(LOOKUP)

This approach starts by defining a dictionary (also called a translation table in this context) by calling the maketrans() method.

Python doesn't enforce having real constant values, but the LOOKUP translation table is defined with all uppercase letters, which is the naming convention for a Python constant. It indicates that the value is not intended to be changed.

The translation table that is created uses the Unicode code points (sometimes called the ordinal values) for each letter in the two strings. As Unicode was designed to be backwards compatible with ASCII and because the exercise uses Latin letters, the code points in the translation table can be interpreted as ASCII. However, the functions can deal with any Unicode character. You can learn more by reading about strings and their representation in the Exercism Python syllabus.

The Unicode value for "G" in the first string is the key for the Unicode value of "C" in the second string, and so on.

In the to_rna() function, the translate() method is called on the input, and is passed the translation table. The output of translate() is a string where all of the input DNA characters have been replaced by their RNA complement in the translation table.

Translation missing: uk.number.nth.ordinalized Sep 2026 · Це було корисно?

Інші підходи до вправи Транскрипція РНК у треку Python

Інші способи, якими наша спільнота розвʼязала цю вправу