Nested Lists, Copying and List Programs in Python Class 11: Aliasing, Linear Search and Frequency
Updated 17 October 2026 · Fact-checked
A nested list holds lists as items and is read with two indices, M[row][column]. The assignment B = A does not copy a list; it makes B another name for the same list, so a change through either name shows in both. A real (shallow) copy is made with A[:], A.copy() or list(A). Standard list programs use a loop with an accumulator, a position variable or a counter.
With B = A both names point to one list, so a change shows in both; A[:] makes a new list, so B is not A.
Illustration drawn for QuestionBuddy.
Understand Nested Lists, Copying (Aliasing) and List Programs: Max, Mean, Linear Search and Frequency (CBSE 11)
Nested lists. An item of a list can itself be a list. For M = [[1, 2, 3], [4, 5, 6]], len(M) is 2 (two rows), M[1] is [4, 5, 6] and M[1][2] is 6. Rows may have different lengths. Traverse with a loop over rows and an inner loop over the items of each row.
Aliasing. B = A copies only the reference. Both names point to one list, so B.append(3) also changes A. The test B is A is True.
Copying. B = A[:], B = A.copy() and B = list(A) build a new list with the same items. After this B is not A and changes to the top level of one do not affect the other. These are shallow copies: if A contains a list, the copy holds the SAME inner list, so changing an inner item shows in both.
Rebinding is not changing. B = B + [4] builds a new list and points B at it; the old list (and any alias) is not changed. B += [4] on a list changes it in place.
Programs.
- Maximum without max(): set big = L[0]; for each x in L, if x > big then big = x. Minimum is similar.
- Mean: add all items to a total and divide by len(L).
- Linear search: compare each item with the key, going from index 0; stop at the first match, or collect all matching indices.
- Frequency: count how often each value occurs, using count() or a counter variable.
L = [4, 7, 2, 7, 9, 7]
x = 7
pos = []
for i in range(len(L)):
if L[i] == x:
pos.append(i)
print(x, "found at", pos, "count", len(pos)) # 7 found at [1, 3, 5] count 3Nested Lists, Copying (Aliasing) and List Programs: Max, Mean, Linear Search and Frequency (CBSE 11): key facts
- Nested indexing
- M[r][c] row r then column c
- len(M) number of rows
- len(M[r]) items in row r
- Indices start at 0.
- Alias versus copy
- B = A same list, two names
- B = A[:] new shallow copy
- A.copy() and list(A) also copy
- A copy is shallow: inner lists are shared.
- Max and min loop
- big = L[0]
- if x > big then big = x
- small = L[0]
- if x < small then small = x
- Start from an item of the list, not from 0.
- Mean and search
- mean = sum of items / len(L)
- linear search compares from index 0
- frequency = L.count(x)
- Mean of numbers is a float in Python 3.
How to answer Nested Lists, Copying (Aliasing) and List Programs: Max, Mean, Linear Search and Frequency (CBSE 11) questions
To answer an aliasing or nested-list question, track which names point to which list.
- 1Draw each list once and mark the names that point to it.
- 2For B = A write that both names share one list; for A[:] or copy() draw a new top-level list.
- 3For nested items remember that the inner lists are shared even after a shallow copy.
- 4For loop programs trace the key variable (big, total, count or position) at each pass.
- 5Write the printed output exactly as Python prints it.
Nested Lists, Copying (Aliasing) and List Programs: Max, Mean, Linear Search and Frequency (CBSE 11) in real life
The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
A shared class timetable
Suppose a class monitor keeps the timetable as a list t = ["Maths", "Science", "English"]. A friend writes f = t to "keep a copy", and later changes f[0] to "Games" to plan a swap.
What happens to t, and what should the friend have written?
Try it first, then show the solutionSolution
- f = t makes f another name for the same list, so f[0] = "Games" changes the list seen by t as well.
- A separate copy needs f = t[:] or f = t.copy().
Answer: t becomes ["Games", "Science", "English"]; the friend should have used f = t[:].
Memory hook: Equal sign shares; slice or copy() duplicates.
Tricks to remember Nested Lists, Copying (Aliasing) and List Programs: Max, Mean, Linear Search and Frequency (CBSE 11)
Short memory aids. Say each one aloud once, then use it on a question the same day.
Equal sign is a second name
B = A gives one list two names; only [:], copy() or list() give two lists.
Use it when: Aliasing questions.
Row first, column second
M[r][c] reads like a spreadsheet cell: row then column.
Use it when: Nested lists.
Start the maximum from the list
Set big = L[0], never 0, so all-negative lists still work.
Use it when: Max and min programs.
Nested Lists, Copying (Aliasing) and List Programs: Max, Mean, Linear Search and Frequency (CBSE 11): solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: Alias and append · 1 mark · MCQBoard level
What is the output?
A = [1, 2]
B = A
B.append(3)
print(A)(a) [1, 2]
(b) [1, 2, 3]
(c) [3]
(d) Error
Try it first, then show the solutionSolution
- B = A makes B point to the same list as A.
- B.append(3) changes that one list to [1, 2, 3], so A shows it too.
Answer: (b) [1, 2, 3]
Example 2: A real copy · 2 marks · Short answerBoard level
Give the output:
A = [1, 2, 3]
B = A[:]
B[0] = 9
print(A, B)Try it first, then show the solutionSolution
- A[:] builds a new list [1, 2, 3] and B points to it.
- B[0] = 9 changes only B: [9, 2, 3].
- A is unchanged.
Answer: [1, 2, 3] [9, 2, 3]
Example 3: Reading a nested list · 4 marks · Short answerHarder board level
Give the output of the program. (4 marks)
M = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
print(M[1][2], M[-1][0], len(M), len(M[0]))
d = 0
for i in range(3):
d += M[i][i]
c = 0
for row in M:
c += row[1]
print(d, c)Try it first, then show the solutionSolution
- M[1] is [4, 5, 6] so M[1][2] = 6; M[-1] is [7, 8, 9] so M[-1][0] = 7; len(M) = 3; len(M[0]) = 3. First print: 6 7 3 3.
- d adds M[0][0] + M[1][1] + M[2][2] = 1 + 5 + 9 = 15.
- c adds the item at index 1 of each row: 2 + 5 + 8 = 15.
- Second print: 15 15.
Answer: 6 7 3 3
15 15
Example 4: Shallow copy trap · 5 marks · Short answerHOTS / competency
Trace the code and explain why A changed even though only B was modified. (5 marks)
A = [1, [2, 3]]
B = A.copy()
B[0] = 10
B[1].append(4)
print(A)
print(B)Try it first, then show the solutionSolution
- A.copy() makes a new outer list B; the items are the same objects: 1 and the inner list [2, 3].
- B[0] = 10 replaces an item in B only, so A[0] stays 1.
- B[1] is the same inner list as A[1]; append(4) changes that shared list to [2, 3, 4].
- A prints [1, [2, 3, 4]] and B prints [10, [2, 3, 4]].
- Reason: a shallow copy copies only the top level, so inner lists are still shared.
Answer: [1, [2, 3, 4]]
[10, [2, 3, 4]]
Example 5: Search and count · 4 marks · Short answerHarder board level
Write a program to search the list L = [4, 7, 2, 7, 9, 7] for 7 and print all positions and the count. Give the output, and the output if the key is 5. (4 marks)
Try it first, then show the solutionSolution
- Use a loop over range(len(L)) and append i to pos when L[i] == x.
- For 7 the matches are at indices 1, 3 and 5, so pos = [1, 3, 5] and the count is 3.
- Output: 7 found at [1, 3, 5] count 3.
- For 5 no index matches: pos = [], count 0. Output: 5 found at [] count 0.
Answer: 7 found at [1, 3, 5] count 3; for 5: 5 found at [] count 0
Where students lose marks in Nested Lists, Copying (Aliasing) and List Programs: Max, Mean, Linear Search and Frequency (CBSE 11)
The slips examiners see most often, and what to write instead.
Mistake: Using = to copy a list
Thinking assignment duplicates the list.
Wrong working
B = A; B.append(5) # A is also changed
Right working
B = A[:]; B.append(5) # A is unchanged
Do this: Use [:], copy() or list().
Usually costs: 1 to 2 marks
Mistake: Starting the maximum at 0
Assuming the list has positive numbers.
Wrong working
big = 0 for L = [-5, -2, -9] gives 0, which is not in the list
Right working
big = L[0] gives -2
Do this: Initialise from the first item.
Usually costs: 1 mark
Mistake: Swapping row and column indices
Writing M[c][r].
Wrong working
M = [[1, 2, 3], [4, 5, 6]]; M[2][1] raises IndexError
Right working
M[1][2] is 6
Do this: Row first, then column.
Usually costs: 1 mark
Exam tips
- In aliasing questions state clearly that the two names refer to one list.
- For nested lists write len(M) and len(M[0]) separately in explanations.
- In program answers include the initialisation line and the print line.
- Give the output for a no-match case if the question asks about a search.
Practice questions on Nested Lists, Copying (Aliasing) and List Programs: Max, Mean, Linear Search and Frequency (CBSE 11)
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · MCQBoard level
Which statement creates a separate copy of the list A?
(a) B = A
(b) B = A[:]
(c) B == A
(d) B is AHint
A slice is a new list.
Answer
(b) B = A[:]
Q2 · 1 mark · Assertion-reasonHarder board level
Assertion (A): After B = A for a list A, the statement B[0] = 100 also changes A[0].
Reason (R): The assignment B = A copies the reference and not the list.
(a) Both A and R are true, and R is the correct explanation of A.
(b) Both A and R are true, but R is not the correct explanation of A.
(c) A is true, but R is false.
(d) A is false, but R is true.Hint
One list, two names.
Answer
(a) Both A and R are true, and R is the correct explanation of A.
Q3 · 3 marks · Short answerHarder board level
Give the output:
a = [1, 2, 3] b = a b = b + [4] print(a, b)(3 marks)
Hint
b + [4] builds a new list.
Answer
b + [4] creates a new list and b is re-pointed to it; a still refers to the old list. Output: [1, 2, 3] [1, 2, 3, 4]
Q4 · 5 marks · Short answerHarder board level
Write a program that finds the largest and smallest item and the mean of L = [12, 5, 19, 8] without using max(), min() or sum(), and give the output. (5 marks)
Hint
Use big, small and total.
Answer
big = L[0]; small = L[0]; total = 0; for x in L: if x > big: big = x; if x < small: small = x; total += x; print(big, small, total / len(L)). Items: largest 19, smallest 5, total 44, mean 44 / 4 = 11.0. Output: 19 5 11.0
Q5 · 4 marks · Short answerHOTS / competency
Give the output and explain it:
g = [[0] * 3] * 2 g[0][0] = 1 print(g)(4 marks)
Hint
Both rows are the same object.
Answer
[0] * 3 makes one list [0, 0, 0]; multiplying by 2 repeats the reference to that same list, so g holds the same inner list twice. g[0][0] = 1 changes it for both rows. Output: [[1, 0, 0], [1, 0, 0]]
Test your recall
Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.
1.What does B = A do for lists?Show answer
Makes B another name for the same list.
2.Name three ways to copy a list.Show answer
A[:], A.copy() and list(A).
3.How do you read row 2, column 1 of M?Show answer
M[2][1].
4.What should big start as in a maximum program?Show answer
The first item, L[0].
5.What is a shallow copy?Show answer
A copy of the outer list only; inner lists are shared.
Nested Lists, Copying (Aliasing) and List Programs: Max, Mean, Linear Search and Frequency (CBSE 11): frequently asked questions
Can rows of a nested list differ in length?
Yes; each row is an independent list.
How do I check that two names share one list?
Use B is A, which is True for an alias.
Is a linear search fast for long lists?
It checks items one by one, so the time grows with the length of the list.