Question: Python list iteration, explain please thank you Q5. List iteration A simple lossless algorithm for compressing a list of Booleans replaces each sequence of consecutive
Q5. List iteration A simple lossless algorithm for compressing a list of Booleans replaces each sequence of consecutive values with the length of that sequence. All lists are assumed to start with (0 or more) Trues. So e.g. True, True, False, True, False, False, Falselis compressed to 12, 1, 1, 3l and [False, False, True] is compressed to lo, 2, 1J Use iteration over lists to define the following function. 10 marks def simple (xs): #simple returns the compressed version of the list of Booleans xs 2, I I, 3 def simple(s): return b False while b in xs: K xs index (b) zs append(k) b not b Zs. append (len(s) return zs
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
