'''lecture_18_copying_sublists.py Explore issues involved in copying sublists Oliver W. Layton CS 151: Computational Thinking: Visual Media Fall 2020 ''' # 1) Explore copying middle row then changing an item in the copy digits = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] # middleRow = digits[1] # print(middleRow) # middleRow[0] = -999 # print(middleRow) # print(digits) # 2) Explore copying 1st two rows then modifying the copy digits = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] # firstTwo = digits[:2] # print(firstTwo) # firstTwo[0][0] = -999 # firstTwo[1][1] = 999 # print(firstTwo) # print(digits) # 3) Access single int, then change it # digits = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] # theFour = digits[1][0] # print(theFour) # theFour = -999 # print(theFour) # print(digits) # How to assign/update values of an item in a list of lists # digits = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] # digits[1][0] = -9999 # print(digits) # 4) Access a list of basic types, but not one of the original sublists # e.g. the 1st two ints in the first sublist digits = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] slice = digits[1][:] print(slice) slice[0] = -999 print(slice) print(digits) # side note # listA = [1, 2, 3] # listB = listA[:] # listB[0] = -999 # print(listA) # print(listB) # 5) Access a list with a sublist of 3 turtle objects and another with 1 turtle object. # Slice the 1st two ints in the first sublist import turtle turtles = [[turtle.Turtle(), turtle.Turtle(), turtle.Turtle()], [turtle.Turtle()]] turtSlice = turtles[0][:2] print(turtles) print(turtSlice)