Nate Brunelle Today: Lists CS1110 Nate Brunelle Today: Lists
Questions?
How to swap temp = lst[-1] Lst[-1] = lst[0] Lst[0] = temp
Last Time Nested lists Aliasing
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)
Tips for fixing bugs in code Know what your code should do Read error messages Believe the error message Print every variable Binary search Test more
Binary search begin Line1 Line2 Line3 Line4 Line5 end Print all the variables Line2 Line3 Was it correct (if so, the problem is later) , or incorrect (if so the problem was earlier? Line4 Line5 end