Learning LibraryBiotech LibraryTeens

Codons: reading RNA three letters at a time

The cell reads RNA in chunks of three. Each three-letter codon names one amino acid — and in code, that's slicing a string into triplets and looking each one up.

The big idea

A codon is a group of three RNA bases that codes for one amino acid, found by reading the sequence in steps of three.

See it in code

1The basics

The cell reads RNA three bases at a time. Slicing pulls out one codon: rna[0:3] is the first triplet, rna[3:6] the next — each a three-letter chunk:

python
rna = "AUGGCUUAA"
print("Full strand:", rna)
print("First codon:", rna[0:3])
print("Second codon:", rna[3:6])
Run it — two codons sliced straight out of the strand:
Full strand: AUGGCUUAA
First codon: AUG
Second codon: GCU

Each slice jumps three bases: 0:3, then 3:6. Do that across the whole strand and you have every codon.

2A step further

Rather than slice by hand, a step-3 range walks the strand for you — range(0, len(rna), 3) gives 0, 3, 6, one start per codon — and we collect the triplets into a list:

python
rna = "AUGGCUUAA"
codons = []
for i in range(0, len(rna), 3):
    codons.append(rna[i:i+3])
print("Codons:", codons)
Run it — the whole strand split into a list of codons:
Codons: ['AUG', 'GCU', 'UAA']

The step-3 range chops the strand into reading frames automatically. Next we give each of these triplets a meaning.

3In our world

With the strand split into triplets, one dictionary maps each codon to its amino acid — a perfect key-to-value lookup. Here it's done in a single comprehension, then each codon is translated:

python
rna = "AUGGCUUAA"
codons = [rna[i:i+3] for i in range(0, len(rna), 3)]
print("Codons:", codons)

table = {"AUG": "Met", "GCU": "Ala", "UAA": "Stop"}
for c in codons:
    print(c, "->", table[c])
Run it — the strand split into codons, each looked up:
Codons: ['AUG', 'GCU', 'UAA']
AUG -> Met
GCU -> Ala
UAA -> Stop

Same triplets as the step before, now each carrying meaning: the dictionary turns every codon into an amino acid in one lookup. AUG is the start signal and UAA is a stop — the cell's punctuation.

The same idea, everywhere

Reading data in fixed-size chunks is a common pattern: bytes into characters, a stream into packets, a list into batches. Pairing that with a lookup table — the dictionary — is how you translate raw units into meaning, whether they're codons, op-codes, or emoji.

Try it yourself

Add "GGC": "Gly" to the table and translate a longer strand. Then shift the reading frame by starting the slice at index 1 — notice how the codons, and the protein, completely change.

The common mistake

Losing the reading frame. Codons must be read in consistent groups of three from the start codon; slice from the wrong position and every triplet after it is garbage. A single inserted base shifts the whole frame — a real and serious kind of mutation.

What it unlocks

Codons rely on dictionaries and list indexing, and assemble into the genetic code and full translation.