CSC108H1 Midterm: UTSG CSC 108 2009_winter_sol
yifanyang and 39659 others unlocked
21
CSC108H1 Full Course Notes
Verified Note
21 documents
Document Summary
Complete the following function according to its docstring description. def clump(l, k): """return a list that is the same as list l, but with the items grouped into sublists of length k (except for the last sublist, which may be shorter). k must be >= 1. Example: clump([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 4) returns the list. Solution: ans = [] subpart = [] for i in range(len(l)): subpart. append(l[i]) if i % k == k - 1: ans. append(subpart) subpart = [] if subpart != []: ans. append(subpart) return ans. Complete the following function according to its docstring description. Hint: media. get_pixel lets you get the pixel at desired coordinates from a picture. You can then either get or set the pixel"s colour. def cutout(p1, p2, x, y, h, w): The rectangle to change has its upper-left corner at pixel (x, y), and has height h and width w. Solution: def cutout(p1, p2, x, y, h, w):