By the end of this module you can do everything below. The objectives and their wording come from the official PCEP-30-03 syllabus.
3.1.1 Construct lists and access their elements
- Create empty and populated lists.
- Store values of the same or different data types in a list.
- Access list elements using positive and negative indexes.
- Extract portions of a list using slicing.
- Use slice start, stop, and step values.
- Create copies of lists using slicing.
3.1.2 Modify, search, sort, and iterate through lists
- Add elements using methods such as
append()andinsert(). - Locate elements using methods such as
index(). - Remove list elements using appropriate methods or the
delkeyword. - Sort list data using the
sorted()function and relevant list methods. - Iterate through list elements using a
forloop. - Initialize and update values while processing a list.
- Use the
inandnot inoperators to test list membership. - Determine the number of elements in a list using the
len()function.
3.1.3 Create, access, and modify multidimensional lists
- Use lists of lists to represent two-dimensional structures such as matrices.
- Use deeper levels of nesting to represent three-dimensional structures such as cubes.
- Access elements in multidimensional lists using multiple indexes.
- Modify values stored in nested lists.