PythiloLesson 15 of 30 · progress kept in this browser

List methods and copies

Lists change in place. These methods modify the list and return None, except pop, which returns what it removed.

xs = [3, 1]
xs.append(4)       # [3, 1, 4]
xs.extend([1, 5])  # [3, 1, 4, 1, 5]
xs.insert(0, 9)    # [9, 3, 1, 4, 1, 5]
xs.remove(1)       # first 1 only
last = xs.pop()    # takes the 5
print(xs, last)    # [9, 3, 4, 1] 5
print(xs.index(4), xs.count(1))  # 2 1

remove and index raise ValueError when the value is not there, so check with in first. pop(0) takes from the front.

Your task

Write move_to_front(items, value) returning a new list with the first occurrence of value moved to the front, leaving items unchanged (a plain copy if value is missing). Write make_grid(rows, cols) returning rows separate lists of cols zeros.