Nate Brunelle Today: Lists CS1110 Nate Brunelle Today: Lists
Questions?
Last Time Loops in loops
Lists in lists x=[[1, 2], [3, 4, 5], [6]] len(x) -> 3 x[1] -> [3,4,5] len(x[1]) -> 3 x[1][0] -> 3 len(x[1][0]) Error
Example of lists in lists Pictures are: A grid of pixels A grid is: A list of rows A row is: A list of pixels A pixel is: A list of 3 numbers (amounts of red, green blue) So a picture is: A list of lists of lists rows of pixels of 3 numbers
Identity, Alias Alias: another name for the same thing
New lists vs. Aliasing Creates a new list: Creates an Alias: List-builder: [x, y, z] Slicing: mylist[start:end:step] Casting: list(collection) Creates an Alias: Assignment: mylist = myotherlist Invoking a function: func(mylist)