Lists — Practice Questions
50 questions. Try each one yourself before checking the answer.
Create fruits = ["apple", "banana", "cherry"]. Print the first and last items using indexing.
Using numbers = [10, 20, 30, 40, 50], print the first three elements and the last two using slicing.
Print the number of items in colors = ["red", "green", "blue", "yellow"].
Start with shopping_list = ["milk", "eggs"]. Add "bread" using .append() and print the list.
Print every item of pets = ["cat", "dog", "hamster"] on its own line using a for loop.
Given numbers = [1, 2, 3, 4, 5], print whether 3 and 10 are each in the list.
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.
Start with numbers = [1, 2, 4, 5]. Use .insert() to add 3 at index 2, then print the list.
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.
Given numbers = [5, 2, 8, 1, 9], sort it in place using .sort(), then reverse it using .reverse(), printing the list after each step.
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].
Given letters = ["a", "b", "c", "b", "d", "b"], print the index of the first "b" and how many times "b" appears.
Given words = ["banana", "kiwi", "apple", "fig"], sort them by length using .sort(key=len).
Create matrix = [[1, 2], [3, 4], [5, 6]]. Print the element at row 1, column 0.
Build a list of squares of numbers 1 to 10 using a for loop and .append() — no comprehensions.
Given numbers = [4, 7, 2, 9, 10, 3, 6], build a new list containing only the even numbers, using a loop.
Given original = [1, 2, 3], create alias = original and copy = original.copy(). Modify original and show that alias changes too, but copy doesn't.
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.
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.
Build a 3x3 matrix using nested for loops and .append(), where matrix[i][j] = i * 3 + j.
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.
Given scores = [78, 92, 85, 64, 90], compute the average manually using a loop (no sum()), and print it.
Given numbers = [4, 7, 2, 9, 10, 3, 6], find the largest and smallest values using a loop, without max()/min().
Given cart = ["apple", "milk", "bread", "apple", "eggs"], remove ONE occurrence of "apple" using .remove() and print the resulting list.
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.
Given inventory = ["pen", "notebook", "eraser"] and quantities = [50, 20, 15], print each item with its quantity using zip().
Given matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], print the sum of each row on its own line, using nested loops.
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)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.
Given products = ["Pen", "Notebook", "Eraser"] and prices = [10.5, 45.0, 5.75], print a formatted, aligned table of both using zip().
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()).
Given nested = [[1, 2, [3, 4]], [5, 6], [7, [8, [9, 10]]]], flatten it into a single flat list using recursion.
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.
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).
Given numbers = [1, 2, 3, 4, 5], reverse it IN PLACE manually using index swapping (without .reverse() or slicing).
Given matrix = [[1, 2, 3], [4, 5, 6]], compute its transpose (rows become columns) manually using nested loops, without zip().
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.
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().
Given numbers = [5, 3, 8, 1, 9, 2], implement bubble sort manually using nested loops (no .sort()/sorted()).
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.
Build a "To-Do List Manager" with a menu loop supporting add, remove, view, and exit, backed by a single list.
Build an "Inventory Tracker" using two parallel lists (items, quantities). Support adding stock, removing stock, and printing a formatted report.
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.
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.
Build a "Matrix Toolkit" with functions matrix_sum(matrix) and matrix_transpose(matrix), then demonstrate both on a sample 2x3 matrix.
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).
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.
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.
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.
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