Python lists, tables and list algorithms
Create 1D and 2D lists, use indexes and iteration, apply list methods and write linear search and bubble sort.
Section 10 · Further programming and testing
Mapped to the Cambridge IGCSE Computer Science 0265 syllabus for exams in 2029. These original explanations and self-checks are independent study support, not Cambridge papers, official marks or grades. Practical programming is taught with worked code and trace tasks; an executable Python workspace and timed digital-exam simulation are not yet available.
Before you begin
- Use the 2029 syllabus for this course. Cambridge specifies Python 3.10 or higher for programming and digital exams for both components. The syllabus currently identifies this route for 2029 only; confirm later-year availability with Cambridge and your school.
Work on paper. Try each question before revealing help, and explain why your method works.
Quick readiness check
Before python lists, tables and list algorithms, which statement is the safest starting point?
What you will learn
- Define, initialise and traverse 1D and 2D lists
- Use the specified list functions and methods
- Write linear-search and bubble-sort algorithms
Lists store related values in order
A list holds multiple items under one variable name. Each item has an index, starting at zero. Use an index variable when reading or updating a particular position; use iteration to visit each item. A two-dimensional list can represent rows and columns, such as a table of scores.
Python provides sum(), max(), min() and len() for common list operations. append() adds an item at the end, insert() adds at a position, pop() removes and returns an item, sort() orders a list in place, and in/not in test membership.
Search and sorting need clear bounds
Linear search compares a target with each element until it is found or the list ends. Bubble sort compares adjacent items and swaps out-of-order values; repeated passes move larger values toward the end until no swaps are needed.
Use valid index ranges: if a list has n elements, its indexes are 0 through n−1. A two-dimensional list needs an outer row index and an inner column index. Test empty, one-item, repeated-value and already sorted cases when writing algorithms.
Pause and explain
Which habit best checks your understanding of python lists, tables and list algorithms?
Worked example
Read row 1, column 2 from grid = [[3,4,5],[6,7,8]].
Show the worked solution
- Indexes start at zero, so row 1 is the second row.
- Column 2 is the third item in that row.
- The value is 8.
Answer grid[1][2] is 8.
Try a topic test
Choose Easy, Normal or Difficult. Save your answers and open worked review after finishing.
Test this topic →From guided practice to a new situation
Write your answer and reasoning first. Use a hint only if you are stuck. The model solution is for self-checking; your written work is not automatically marked.
Given values = [4, 9, 2], find len(values), values[1] and sum(values).
Give me a hint
Use zero-based indexing and add each item for the total.
Compare my reasoning
- There are 3 items.
- Index 1 is the second item, 9.
- 4 + 9 + 2 = 15.
3, 9 and 15
Look for these in your work
- Length
- Index
- Total
Write a loop that counts how many values in marks = [38, 72, 65, 49] are at least 50.
Give me a hint
Initialise a counter and test every value.
Compare my reasoning
- Set passed = 0.
- For each mark, if mark >= 50, add one.
- The qualifying values are 72 and 65, so print 2.
passed = 0 for mark in marks: if mark >= 50: passed += 1
Look for these in your work
- Counter set
- All items visited
- Boundary rule applied
Perform one bubble-sort pass on [5, 1, 4]. Explain why one pass does not guarantee the whole list is sorted.
Give me a hint
Compare the first two, then the next adjacent pair.
Compare my reasoning
- 5 and 1 swap: [1, 5, 4].
- 5 and 4 swap: [1, 4, 5].
- This example happens to finish sorted, but longer lists can need more passes; stop when a complete pass makes no swaps.
After this pass: [1, 4, 5]; in general repeat passes until no swaps occur.
Look for these in your work
- Comparisons shown
- Pass result
- General stopping rule
Common mistakes
- Using one-based indexes.
- Calling sort() as though it returns a new sorted list.
- Accessing an index equal to the list length.
What can you explain now?
What is the index of the first list item?
Compare with the explanation
0
Python list indexing starts at zero.
After trying it yourself, choose your next review. This is your self-assessment.
Your review choice appears on Today. Sign in to sync it across devices.
Make it stick
How do zero-based indexes, iteration and list methods support searching and sorting?
If you needed the solution, close it and solve the problem again from a blank page. A correct answer is stronger when you can explain the reason for each step.