need help with this python assigment Part II: Run-length Decoding (5 points) Now
ID: 3817048 • Letter: N
Question
need help with this python assigment
Part II: Run-length Decoding (5 points) Now write the function rld that performs a run-length decoding of a string that was encoded using the rle function described above. The function's 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 Homework #3 Page 2 CSE 101 Spring 2017 drawn from the set 1#, &, Y. You may assume that the input string and the flag character are both valid. Examples: Function Call Return Value rld ('XYZ A6GGT C6TTT A 14KK' XYZAAAAAAALAGGTCCCCCCTT TAAAAAAAAAAAAAAAKK' GGGGG rld G5', rld & G15ABC', 's') GGGGGGGGGGGGGGGABC' rld ('ABCCDEF GGG', AB (CCDEFGGG' 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.Explanation / Answer
Since you haven't mentioned your function rle() , assuming your encoding like this : (AAA,*) -> *A3
(Hope its correct)
#fn.py
def fn(enc, i):
j=i
while (j<len(enc) and enc[j].isdigit()):
j = j+1
return j
def rld(enc , c):
i=0;
ans='';
while i < len(enc) :
if enc[i] != c :
ans = ans+enc[i];
i=i+1
else :
i = i+1
k = fn(enc, i+1)
for j in range(0,int(enc[i+1:k])) :
ans = ans + enc[i]
i = k
return ans
print (rld('#G5','#'))
print (rld('XYZ*A6GGT*C6TTT*A14KK', '*'))
#write other inputs here
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.