Question: PLEASE CODE IN PYTHON Run-length encoding is a simple compression scheme best used when a data-set consists primarily of numerous, long runs of repeated characters.
PLEASE CODE IN PYTHON
Run-length encoding is a simple compression scheme best used when a data-set consists primarily of numerous, long runs of repeated characters. For example, AAAAAAAAAA is a run of 10 As. We could encode this run using a notation like *A10, where the * is a special flag character that indicates a run, A is the symbol in the run, and 10 is the length of the run. As another example, the string
KKKKKKKKKKKKKBCCDDDDDDDDDDDDDDDKKKKKMNUUUGGGGG
would be encoded
$K13BCC$D15$K5MNUUU$G5
assuming in this case that $ is the flag character. For the sake of this problem we will assume that the input strings to be encoded contain only uppercase letters from the Latin alphabet and that no run is longer than 99 characters long. Flag characters will be chosen only from the set {#, $, &, *}. Note that single letters (M), runs of two letters (CC), and runs of three letters (UUU) are not encoded, as doing so does not save memory or actually compress the data. Do you see why that is the case?
Now write the function rld() that performs a run-length decoding of a string that was encoded using the rle() function described above. The functions arguments are a non-empty string to decode and the character to use as the flag character. The input string consists of a properly-formatted run-length encoding, and the flag character is drawn from the set {#, $, &, *}. You may assume that the input string and the flag character are both valid.
Examples:
rld(XYZ*A6GGT*C6TTT*A14KK, *) XYZAAAAAAGGTCCCCCCTTTAAAAAAAAAAAAAAKK
rld(#G5, #) GGGGG
rld(&G15ABC, &) GGGGGGGGGGGGGGGABC
ld(ABCCDEFGGG, $) ABCCDEFGGG
Note that the quotation marks displayed in the return values are there to emphasize that the return values are strings. You should not add quotation marks to your return values.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
