Python · Python Collections

Lists — Practice Questions

50 questions. Try each one yourself before checking the answer.

Q1IndexingEasy

Create fruits = ["apple", "banana", "cherry"]. Print the first and last items using indexing.

Q2SlicingEasy

Using numbers = [10, 20, 30, 40, 50], print the first three elements and the last two using slicing.

Q3len()Easy

Print the number of items in colors = ["red", "green", "blue", "yellow"].

Q4append()Easy

Start with shopping_list = ["milk", "eggs"]. Add "bread" using .append() and print the list.

Q5forEasy

Print every item of pets = ["cat", "dog", "hamster"] on its own line using a for loop.

Q6MembershipEasy

Given numbers = [1, 2, 3, 4, 5], print whether 3 and 10 are each in the list.

Q7extend()Easy

Start with list1 = [1, 2, 3] and list2 = [4, 5, 6]. Use .extend() to add all of list2's items into list1, then print list1.

Q8insert()Easy

Start with numbers = [1, 2, 4, 5]. Use .insert() to add 3 at index 2, then print the list.

Q9remove() / pop()Easy

Start with numbers = [10, 20, 30, 40]. Use .remove() to delete 20 by value, then .pop() to remove the last item. Print the list after each step.

Q10sort() / reverse()Easy

Given numbers = [5, 2, 8, 1, 9], sort it in place using .sort(), then reverse it using .reverse(), printing the list after each step.

Q11SlicingMedium

Given numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], print every second element using a step-slice, and the list reversed using [::-1].

Q12index() / count()Medium

Given letters = ["a", "b", "c", "b", "d", "b"], print the index of the first "b" and how many times "b" appears.

Q13sort() with keyMedium

Given words = ["banana", "kiwi", "apple", "fig"], sort them by length using .sort(key=len).

Q14Nested ListsMedium

Create matrix = [[1, 2], [3, 4], [5, 6]]. Print the element at row 1, column 0.

Q15List BuildingMedium

Build a list of squares of numbers 1 to 10 using a for loop and .append() — no comprehensions.

Q16FilteringMedium

Given numbers = [4, 7, 2, 9, 10, 3, 6], build a new list containing only the even numbers, using a loop.

Q17CopyingMedium

Given original = [1, 2, 3], create alias = original and copy = original.copy(). Modify original and show that alias changes too, but copy doesn't.

Q18clear() / delMedium

Given numbers = [1, 2, 3, 4, 5], delete the item at index 2 using del, then empty the whole list using .clear(), printing after each step.

Q19List ConcatenationMedium

Given list1 = [1, 2, 3] and list2 = [4, 5, 6], create a NEW combined list using + (without modifying either original), and print all three lists.

Q20Nested ListsMedium

Build a 3x3 matrix using nested for loops and .append(), where matrix[i][j] = i * 3 + j.

Q21Real-WorldMedium

Build a "To-Do List" that starts empty. Ask the user to enter 3 tasks one at a time, appending each, then print the full list.

Q22Real-WorldMedium

Given scores = [78, 92, 85, 64, 90], compute the average manually using a loop (no sum()), and print it.

Q23AlgorithmicMedium

Given numbers = [4, 7, 2, 9, 10, 3, 6], find the largest and smallest values using a loop, without max()/min().

Q24Real-WorldMedium

Given cart = ["apple", "milk", "bread", "apple", "eggs"], remove ONE occurrence of "apple" using .remove() and print the resulting list.

Q25AlgorithmicMedium

Given numbers = [1, 2, 2, 3, 4, 4, 4, 5], count how many duplicates exist (any value appearing more than once) using .count() in a loop, keeping track of ones already reported.

Q26Real-WorldMedium

Given inventory = ["pen", "notebook", "eraser"] and quantities = [50, 20, 15], print each item with its quantity using zip().

Q27Nested ListsMedium

Given matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], print the sum of each row on its own line, using nested loops.

Q28DebuggingMedium

The following code is meant to remove all even numbers from a list, but it skips some. Find and fix the bug.

numbers = [1, 2, 3, 4, 5, 6]
for number in numbers:
    if number % 2 == 0:
        numbers.remove(number)
print(numbers)
Q29sort() vs sorted()Medium

Given numbers = [3, 1, 4, 1, 5], show the difference between sorted(numbers) (returns a new list) and numbers.sort() (sorts in place), printing numbers after each.

Q30FormattingMedium

Given products = ["Pen", "Notebook", "Eraser"] and prices = [10.5, 45.0, 5.75], print a formatted, aligned table of both using zip().

Q31AlgorithmicHard

Given numbers = [1, 2, 2, 3, 4, 4, 5], build a new list with duplicates removed while preserving the original order (don't use set()).

Q32AlgorithmicHard

Given nested = [[1, 2, [3, 4]], [5, 6], [7, [8, [9, 10]]]], flatten it into a single flat list using recursion.

Q33AlgorithmicHard

Given numbers = [1, 2, 3, 4, 5, 6, 7] and k = 3, rotate the list left by k positions using slicing, without using any library.

Q34AlgorithmicHard

Given two sorted lists list1 = [1, 3, 5, 7] and list2 = [2, 4, 6, 8], merge them into a single sorted list using a manual two-pointer walk (not sorted() on the combined list).

Q35AlgorithmicHard

Given numbers = [1, 2, 3, 4, 5], reverse it IN PLACE manually using index swapping (without .reverse() or slicing).

Q36Nested ListsHard

Given matrix = [[1, 2, 3], [4, 5, 6]], compute its transpose (rows become columns) manually using nested loops, without zip().

Q37AlgorithmicHard

Given numbers = [10, 22, 9, 33, 21, 50, 41, 60], find the length of the longest run of strictly increasing consecutive numbers, using a single pass.

Q38CopyingHard

Given matrix = [[1, 2], [3, 4]], create a shallow copy with .copy() and modify a nested row through it. Show that the original matrix is affected too, then fix it using copy.deepcopy().

Q39AlgorithmicHard

Given numbers = [5, 3, 8, 1, 9, 2], implement bubble sort manually using nested loops (no .sort()/sorted()).

Q40AlgorithmicHard

Given a sorted list numbers = [2, 5, 8, 12, 16, 23, 38, 45] and a target, implement binary search manually (no linear scan) and return the index or -1.

Q41Mini-ProjectMini-Project

Build a "To-Do List Manager" with a menu loop supporting add, remove, view, and exit, backed by a single list.

Q42Mini-ProjectMini-Project

Build an "Inventory Tracker" using two parallel lists (items, quantities). Support adding stock, removing stock, and printing a formatted report.

Q43Mini-ProjectMini-Project

Build a "Student Grade Processor". Given a list of (name, score) pairs stored as small lists, print each student's pass/fail status and the class average.

Q44Mini-ProjectMini-Project

Build a "Duplicate Finder & Remover" tool. Ask the user to enter 8 numbers one at a time into a list, then print the duplicates found and a cleaned, duplicate-free version.

Q45Mini-ProjectMini-Project

Build a "Matrix Toolkit" with functions matrix_sum(matrix) and matrix_transpose(matrix), then demonstrate both on a sample 2x3 matrix.

Q46InterviewInterview

Explain and demonstrate why mutating a list while iterating over it (with for) is dangerous, showing both the buggy pattern and the safe fix (iterating over a copy, or building a new list).

Q47InterviewInterview

Demonstrate the classic mutable-default-argument pitfall in the context of lists: a function that appends to a default-argument list accumulates values across unrelated calls unless fixed with None.

Q48InterviewInterview

Explain the time-complexity difference between checking membership (in) on a list versus appending to the end versus inserting at the front, and demonstrate with a comment-annotated example.

Q49InterviewInterview

Explain and demonstrate the difference between == and is when comparing two lists with identical contents, tying it back to the identity-vs-equality concept from the Operators module.

Q50CapstoneInterview

Build a "List Toolkit Report" — the most complete demonstration in this module. Given numbers = [5, 3, 8, 1, 9, 3, 5, 2], manually compute (using loops, no built-in sum/max/min/sorted): total, average, max, min, a duplicate-free version preserving order, and a sorted copy (via your own bubble sort) — all printed in a labeled report.

Still stuck on something?

Book a free 1-on-1 session and we'll work through it together.

Book a Free Session