This Week's Worksheet ⬇️
mentor06.pdf
mentor06_sol.pdf
List Review
What is List?
- sequence of elements
- square brackets denote Python lists
- Lists can contain any type of object, even other lists
- empty brackets denote an empty list []
List Operations
- Creating new list
lst + lst
lst * n
lst[i:j]
list(lst)
- Zero indexing
- List slicing
- Inclusive start, exclusive end
- Deep vs. Shallow copy
- Shallow copy: when you copy a nested list, copy pointers to the nested list
- Deep copy: make a new copy of the nested list
List Operators
len()
returns length of list
in
operator checks if the list contains an element
+
operator concatenates two lsits
- Unpacking elements: x, y = [1, 2]
List Comprehension