I would like to build an an encoder and decoder using text coding.
A string “AAABBBBCDDDDDDDDDDEEDDDD” as input, returning a string “A3B4C1D10E2D4”, where each alphabet symbol is followed by its frequency in the string. The decoder reverses the process.
Would like help getting started in python.
One possible solution for the cnoder would be to simply iterate over the string and count the character occurences, not very fancy but O(n).
For the decoder you could use a regular expression which splits the string up nicely for you, no need to write your own parser.
given your test input
results in
One more note, there’s no real reason to use yield here, you could of course also build the strings in the en-/decode functions first, then return.