Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a python code which can make the same output as the image >f (0, 0, 10) 2

ID: 3711610 • Letter: W

Question

write a python code which can make the same output as the image

>f (0, 0, 10) 2 Here is L: D The decomposition of L into increasing sublists is: Cl >f (0, 1, 10) Here is L: [6] The decomposition of L into increasing sublists is: [[6]] f (0, 2, 10) 2 Here is L [6, 6] The decomposition of L into increasing sublists is: [[6], [6]] 2 Here is L: [2, 9] The decomposition of L into increasing sublists is: [[2, 9]] >f (0, 3, 10) Here is L: [6, 6, 0] The decomposition of L into increasing sublists is: [[6], [6], [0]] 2 4 Here is L [2, 9, 1, 4] The decomposition of L into increasing sublists is: [[2, 9], [1, 4]] >f (20, 5, 10) Here is L: [10, 2, 4, 10, 10] The decomposition of L into increasing sublists is: [[10], [2, 4, 10], [10]] 2 Here is L: [4, 18, 2, 8, 3, 15, 14, 15, 20, 12] The decomposition of L into increasing sublists is: [[4, 18], [2, 8], [3, 15], 3 2 2 [14, 15, 20], [12]]

Explanation / Answer

# I am using numpy to generate list of n random number within range(minn, maxn) , maxn is assumed to be greater than 0, and If minn is greater than maxn, it is defaulted to zero. Below is the code

import numpy as np

def f(minn, n, maxn):

assert maxn >= 0
if minn > maxn:
minn = 0
L = np.random.randint(minn, maxn+1, n).tolist()
print "Here is L:",L
DL = []
pre_e = None
for e in L:
if pre_e is None or e <= pre_e:
DL.append([])
DL[-1].append(e)
pre_e = e
print "The decompostion of L into increasing sublists is:",DL