Apply ordered subword merges
Implement bpe_encode(text, merges) using character symbols and an ordered list of string pairs. Each merge makes one left-to-right nonoverlapping pass, combining matched adjacent symbols by concatenation. Require string text and pairs of two nonempty strings. Return the final symbol list. This is an educational character-based encoder, not a production byte-level tokenizer and not a merge-learning algorithm.
Your task
- Complete the starter function using the contract above.
- Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
- Run tests to record your result, then compare with the explained reference solution.
Examples
EXAMPLE 1
Inputbpe_encode("banana", [("a","n"),("an","a")])
Output["b", "an", "ana"]
EXAMPLE 2
Inputbpe_encode("aaaa", [("a","a")])
Output["aa", "aa"]
Implement the function, then run the tests.
Ctrl / ⌘ + Enter to test · Shift + Tab leaves editor