Lists Class 11: List Operations, Methods, Nested Lists and List Programs in Python
Updated 14 October 2026 · Fact-checked
A list in Python is a mutable, ordered sequence of items of any type in square brackets. In CBSE Class 11 Computer Science you learn indexing and slicing, concatenation, repetition and membership, traversal, the methods from append() and insert() to pop(), sort() and sorted(), nested lists, and programs for maximum, minimum, mean, linear search and frequency counts.
What Lists is about
Lists is part of Unit II, Computational Thinking and Programming - 1, which carries 45 of the 70 theory marks in the school annual exam. Output questions turn on whether a method changes the list in place and what it returns; programs ask for search, statistics and counting.
The 2026-27 syllabus lists: introduction, indexing, list operations (concatenation, repetition, membership and slicing), traversing a list using loops, the functions and methods len(), list(), append(), extend(), insert(), count(), index(), remove(), pop(), reverse(), sort(), sorted(), min(), max(), sum(), nested lists, and suggested programs: maximum, minimum and mean of numbers in a list, linear search, and counting the frequency of elements.
NCERT section 9.7 (a list as an argument to a function) uses user-defined functions, which CBSE teaches in Class XII, so it is left out. Every program below has been run in Python 3.
Weightage: This chapter is part of Unit II, Computational Thinking and Programming - 1, which carries 45 of the 70 theory marks in the school annual exam together with Introduction to Problem Solving, Getting Started with Python, Flow of Control, Strings, Tuples and Dictionaries and Introduction to Python Modules.Source: CBSE Computer Science (083) syllabus 2026-27, Class XI distribution of marks, Unit II Computational Thinking and Programming - 1
Key concepts
- Creating lists and indexing
- NCERT section NCERT 9.1
A list is an ordered sequence of items separated by commas inside square brackets: marks = [78, 91, 66]. Items can be of different types (['Asha', 16, 72.5, True]), and a list can contain another list. [] is the empty list. list() converts another sequence into a list: list('abc') = ['a', 'b', 'c'], list(range(3)) = [0, 1, 2].
Items are accessed by index exactly as in strings: 0 to n - 1 from the left and -1 to -n from the right; an index outside the range raises IndexError. len(L) gives the number of items (a nested list counts as one item).
Worked example
L = [10, 'ten', [1, 0], 10.0]. Give len(L), L[1], L[-2], L[2][1], L[1][0].
Try it first, then show the solutionSolution
- Four items (the inner list is one item): len = 4.
- L[1] = 'ten'; L[-2] = [1, 0]; L[2][1] = 0.
- L[1][0] indexes the string 'ten': 't'.
Answer: 4, 'ten', [1, 0], 0, 't'
- Lists are mutable
- NCERT section NCERT 9.1.2
Unlike strings and tuples, lists are mutable: items can be changed, added and removed in place.
- change one item: L[1] = 99
- change a slice: L[0:2] = ['a', 'b', 'c'] (the slice may be replaced by a list of a different length)
- delete: del L[0] or del L[1:3]
Because the same list object is changed, any other name referring to it sees the change (see copying).
Worked example
Give the output:
L = [5, 10, 15, 20, 25] L[1] = 11 L[2:4] = [0] print(L) del L[-1] print(L, len(L))Try it first, then show the solutionSolution
- After L[1] = 11: [5, 11, 15, 20, 25].
- Replacing the slice of two items [15, 20] with one item [0]: [5, 11, 0, 25].
- del L[-1] removes 25.
Answer: [5, 11, 0, 25]
[5, 11, 0] 3- List operations: +, *, in, slicing
- NCERT section NCERT 9.2
- Concatenation L1 + L2 makes a new list with the items of both; both operands must be lists ([1] + 2 is a TypeError).
- Repetition L * n repeats the items: [0] * 3 = [0, 0, 0].
- Membership x in L checks whether x is an item of L (not part of an item): 2 in [1, 2, 3] is True; 2 in [[1, 2]] is False.
- Slicing L[start:stop:step] gives a new list, stop excluded, exactly as for strings; L[::-1] is a reversed copy and L[:] is a full copy.
Lists can be compared with == (same items in the same order).
Worked example
A = [1, 2, 3], B = ['x', 'y']. Give A + B, B * 2, 'y' in B, [2, 3] in A, A[::-1], (A + B)[2:4].
Try it first, then show the solutionSolution
- A + B = [1, 2, 3, 'x', 'y']; B * 2 = ['x', 'y', 'x', 'y'].
- 'y' is an item: True. [2, 3] is not an item of A (it is a slice): False.
- A[::-1] = [3, 2, 1]; (A + B)[2:4] = [3, 'x'].
Answer: [1, 2, 3, 'x', 'y'], ['x', 'y', 'x', 'y'], True, False, [3, 2, 1], [3, 'x']
- Traversing a list
- NCERT section NCERT 9.3
Visit each item with a for loop:
- by item: for x in L: ... (cannot change the list's items through x)
- by index: for i in range(len(L)): ... L[i] (needed to change items in place or to know positions)
- with a while loop: i = 0; while i < len(L): ...; i += 1
To change every item, use the index form: for i in range(len(L)): L[i] = L[i] * 2.
Worked example
Give the output and explain the difference:
L = [1, 2, 3] for x in L: x = x * 10 print(L) for i in range(len(L)): L[i] = L[i] * 10 print(L)Try it first, then show the solutionSolution
- In the first loop x is a separate name; changing x does not change the list.
- In the second loop L[i] = ... changes the list items in place.
Answer: [1, 2, 3]
[10, 20, 30]- Methods that add and remove items
- NCERT section NCERT 9.4, Table 9.1
These change the list in place and (except pop) return None.
- append(x): adds x as one item at the end. L.append([4, 5]) adds a single nested list.
- extend(iterable): adds each item of a list (or other sequence) at the end. L.extend([4, 5]) adds 4 and 5; L.extend('ab') adds 'a' and 'b'.
- insert(i, x): puts x before index i (so x ends up at index i). An index beyond the end simply appends.
- remove(x): deletes the first occurrence of the value x; ValueError if x is absent.
- pop([i]): removes and returns the item at index i (default: the last item); IndexError on an empty list or a bad index.
- del L[i] is a statement that deletes by position and returns nothing.
Worked example
Give the output:
L = [3, 6, 9] L.append([12]) L.extend([15, 18]) L.insert(1, 4) print(L) print(L.pop(), L.pop(0)) L.remove(9) print(L)Try it first, then show the solutionSolution
- append adds [12] as one item: [3, 6, 9, [12]].
- extend adds 15 and 18: [3, 6, 9, [12], 15, 18]; insert 4 at index 1: [3, 4, 6, 9, [12], 15, 18].
- pop() returns 18; pop(0) returns 3. remove(9) deletes the value 9.
Answer: [3, 4, 6, 9, [12], 15, 18]
18 3
[4, 6, [12], 15]- Counting, searching, ordering and built-in functions
- NCERT section NCERT 9.4, Table 9.1
- count(x): number of times x occurs.
- index(x): index of the first occurrence of x; ValueError if absent.
- reverse(): reverses the list in place; returns None.
- sort(): sorts the list in place in ascending order; sort(reverse=True) for descending; returns None. Items must be comparable (mixing int and str raises TypeError). Strings sort by character codes, so uppercase before lowercase.
- sorted(L): a built-in function that returns a new sorted list and leaves L unchanged; works on any sequence.
- min(L), max(L), sum(L): smallest, largest, total (sum needs numbers).
- len(L): number of items; list(seq): makes a list.
A common trap: L = L.sort() makes L None, because sort() returns None.
Worked example
Give the output:
L = [40, 10, 30, 10, 20] S = sorted(L) print(S, L) L.sort(reverse=True) print(L, L.count(10), L.index(10)) print(min(L), max(L), sum(L) / len(L)) print(L.reverse())Try it first, then show the solutionSolution
- sorted returns a new list; L is unchanged.
- sort(reverse=True) changes L to [40, 30, 20, 10, 10]; 10 occurs twice; its first index is now 3.
- min 10, max 40, mean 110 / 5 = 22.0.
- reverse() changes L but returns None, which is printed.
Answer: [10, 10, 20, 30, 40] [40, 10, 30, 10, 20]
[40, 30, 20, 10, 10] 2 3
10 40 22.0
None- Nested lists
- NCERT section NCERT 9.5
A list can contain lists, giving a table-like structure: M = [[1, 2, 3], [4, 5, 6]] has 2 rows and 3 columns. M[i] is row i and M[i][j] is the item in row i, column j. len(M) is the number of rows and len(M[0]) the number of columns. Use nested loops to traverse: the outer loop over rows, the inner over the items of each row.
Worked example
marks = [[78, 85, 90], [66, 72, 58], [91, 88, 95]] holds three students' marks in three subjects. Print each student's total and the class total in subject 2 (index 1).
Try it first, then show the solutionSolution
marks = [[78, 85, 90], [66, 72, 58], [91, 88, 95]] for row in marks: print(sum(row), end=' ') print() t = 0 for row in marks: t += row[1] print(t)- Totals: 253, 196, 274. Column 1: 85 + 72 + 88 = 245.
Answer: 253 196 274
245- Copying lists (aliasing)
- NCERT section NCERT 9.6
B = A does not copy a list: it makes B a second name (an alias) for the same list, so a change through B also shows through A. To get an independent copy of a simple list use any of:
- B = A[:] (slicing)
- B = list(A)
- B = A.copy()
Then A is B is False, though A == B is True until one of them changes.
Worked example
Give the output:
A = [1, 2, 3] B = A C = A[:] B.append(4) C.append(5) print(A, B, C)Try it first, then show the solutionSolution
- B is the same list as A, so appending 4 through B changes A.
- C is a separate copy; appending 5 changes only C.
Answer: [1, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 5]
- Suggested programs: max, min, mean, linear search, frequency
- NCERT section Syllabus suggested programs; NCERT 9.8
The syllabus names these programs. Know both the built-in way and the loop way.
- Maximum/minimum without max()/min(): start with big = L[0], then compare every item and update.
- Mean: sum(L) / len(L), or add in a loop.
- Linear search: compare the key with each item from the first; stop (break) when found and report the position; if the loop ends without a match, report not found. In the worst case it checks every item.
- Frequency of elements: for each distinct item, count its occurrences (L.count(x), or a loop), taking care to report each value once.
Worked example
Write a program that does a linear search for 27 in [12, 45, 27, 8, 27] and reports the first position (counting from 1) and the number of comparisons made.
Try it first, then show the solutionSolution
L = [12, 45, 27, 8, 27] key = 27 found = False for i in range(len(L)): if L[i] == key: found = True break if found: print('Found at position', i + 1, 'after', i + 1, 'comparisons') else: print('Not found after', len(L), 'comparisons')- 27 is at index 2, so position 3; three comparisons were made.
Answer: Found at position 3 after 3 comparisons
Lists in real life
Each concept, met in an everyday situation. Read the situation, answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
Stack-like use of append and pop
Suppose a shopping app keeps your cart as a list: ['pen', 'notebook', 'bag']. You add a 'bottle' and then press 'remove last item' twice.
Which list operations model this, and what is left in the cart?
Try it first, then show the solutionSolution
- Add: cart.append('bottle') → ['pen', 'notebook', 'bag', 'bottle'].
- Remove last twice: cart.pop() returns 'bottle', then 'bag'.
Answer: ['pen', 'notebook'] is left.
Memory hook: append adds at the end; pop() takes from the end.
Frequency counting
Imagine a class poll on the sport each student likes best stored as ['cricket', 'football', 'cricket', 'kabaddi', 'cricket', 'football'].
Find how many votes each sport got using list methods.
Try it first, then show the solutionSolution
- Distinct sports in order: cricket, football, kabaddi.
- votes.count('cricket') = 3, count('football') = 2, count('kabaddi') = 1.
Answer: cricket 3, football 2, kabaddi 1.
Memory hook: count() answers 'how many times?'
sorted() keeps the original
Suppose a teacher has the roll-call list of marks in roll-number order and wants to see the top three marks without disturbing the roll order.
Which should she use, sort() or sorted(), and how?
Try it first, then show the solutionSolution
- sort() would reorder the roll-call list itself.
- top = sorted(marks, reverse=True)[:3] gives a new list and leaves marks unchanged.
Answer: sorted(marks, reverse=True)[:3].
Memory hook: sorted() makes a sorted copy; sort() rearranges the original.
Topics in this chapter
Lists: syntax and key facts
- Add items
- append(x): one item at the end; extend(seq): each item at the end; insert(i, x): before index i
- All return None.
- Remove items
- remove(x): first value x; pop(i): by index, returns the item (default last); del L[i]
- remove → ValueError if absent; pop → IndexError if empty.
- Order
- L.sort() / L.reverse(): in place, return None; sorted(L): new list
- sort(reverse=True) for descending.
- Look-up
- count(x), index(x), x in L, len(L), min, max, sum
- index gives the first occurrence.
- Copy
- B = A (alias); B = A[:] or list(A) or A.copy() (copy)
- Aliases share changes.
- Nested access
- M[i][j]: row i, column j; rows = len(M), columns = len(M[0])
- Use nested loops to traverse.
How the school exam asks Lists
The question patterns to expect, and the method that works for each.
| Question type | How it is asked | Method |
|---|---|---|
| Predict the output | A list changed by several methods, then printed (2-3 marks). | Write the list after each statement; note which methods return None and what pop returns. |
| Differentiate | append and extend, remove and pop, sort and sorted, del and remove (2 marks). | Say what each takes (value or index, item or sequence), what it returns and whether it changes the list. |
| Write a program | Max, min, mean; linear search; frequency of each element; even/odd split; second largest; remove duplicates (3-5 marks). | Use a loop with clear variable names; avoid changing a list while looping over it. |
| Nested lists | Access M[i][j], row or column totals, diagonal sums (2-3 marks). | Outer loop for rows, inner loop for columns; check indices with len(). |
| Error spotting | Why does L.remove(7) or L[10] fail, or why is L None after L = L.sort()? (1-2 marks) | Name the error (ValueError, IndexError, None return) and correct the line. |
Tricks to remember Lists
Short memory aids. Say each one aloud once, then use it on a question the same day.
Append = one bag, extend = empty the bag
append puts the whole bag in as one item; extend tips out its contents one by one.
Use it when: append versus extend.
remove by value, pop by position
Remove the Value; Pop the Position (and pop gives it back).
Use it when: remove versus pop.
In-place methods say None
append, extend, insert, remove, sort, reverse all return None; only pop hands something back.
Use it when: Output questions that print a method call.
sorted = new, sort = same
The '-ed' version gives you a new list.
Use it when: sort versus sorted.
B = A is a nickname
Giving the list a second name does not make a second list.
Use it when: Aliasing questions.
Lists: exam-level solved questions
Ordered from exam level to HOTS. Cover the solution, write your own, then compare step by step.
Example 1: Frequency of each element · 3 marks · Short answerExam level
Write a program to print the frequency of each distinct element of [4, 7, 4, 2, 7, 4, 9] once, in order of first appearance.
Try it first, then show the solutionSolution
L = [4, 7, 4, 2, 7, 4, 9] done = [] for x in L: if x not in done: print(x, 'occurs', L.count(x), 'times') done.append(x)- done keeps the values already reported so that each is printed once.
Answer: 4 occurs 3 times
7 occurs 2 times
2 occurs 1 times
9 occurs 1 times
Example 2: Second largest without sorting · 3 marks · Short answerHOTS / competency
Write a program to find the second largest distinct value in [56, 91, 73, 91, 88] in one pass, without sort() or max().
Try it first, then show the solutionSolution
L = [56, 91, 73, 91, 88] first = second = None for x in L: if first is None or x > first: second = first first = x elif x != first and (second is None or x > second): second = x print(first, second)- The repeated 91 is skipped by x != first, so 88 is the second largest distinct value.
Answer: 91 88
Example 3: Method trace · 3 marks · Short answerHarder exam level
Give the output:
L = ['b', 'a', 'd']
M = L
M += ['c']
L.sort()
print(M)
N = sorted(L, reverse=True)
print(N, L is M, N is L)
print(L.remove('a'), L)Try it first, then show the solutionSolution
- M is an alias; M += ['c'] extends the same list: ['b', 'a', 'd', 'c'].
- L.sort() sorts that list: ['a', 'b', 'c', 'd'], so M shows the same.
- N is a new list ['d', 'c', 'b', 'a']; L is M True; N is L False.
- remove returns None; L becomes ['b', 'c', 'd'].
Answer: ['a', 'b', 'c', 'd']
['d', 'c', 'b', 'a'] True False
None ['b', 'c', 'd']
Example 4: Matrix diagonal · 3 marks · Short answerHarder exam level
For M = [[2, 7, 6], [9, 5, 1], [4, 3, 8]], print the sum of the main diagonal, the sum of the other diagonal and the sum of each column.
Try it first, then show the solutionSolution
M = [[2, 7, 6], [9, 5, 1], [4, 3, 8]] n = len(M) d1 = d2 = 0 for i in range(n): d1 += M[i][i] d2 += M[i][n - 1 - i] print(d1, d2) for j in range(n): c = 0 for i in range(n): c += M[i][j] print(c, end=' ')- Main diagonal 2 + 5 + 8 = 15; other 6 + 5 + 4 = 15; columns 15, 15, 15 (it is a magic square).
Answer: 15 15
15 15 15
Example 5: Remove duplicates keeping order · 2 marks · Short answerHarder exam level
Write a program that removes duplicates from ['red', 'blue', 'red', 'green', 'blue'] keeping the first occurrence of each.
Try it first, then show the solutionSolution
L = ['red', 'blue', 'red', 'green', 'blue'] U = [] for c in L: if c not in U: U.append(c) print(U)
Answer: ['red', 'blue', 'green']
Example 6: Shifting items · 3 marks · Short answerHOTS / competency
Write a program to rotate [1, 2, 3, 4, 5] two places to the right (the last two items come to the front) using pop() and insert(), and give the result.
Try it first, then show the solutionSolution
L = [1, 2, 3, 4, 5] for k in range(2): L.insert(0, L.pop()) print(L)- First pass: pop 5, insert at 0 → [5, 1, 2, 3, 4]. Second: pop 4 → [4, 5, 1, 2, 3].
Answer: [4, 5, 1, 2, 3]
Example 7: Errors in list code · 2 marks · Short answerExam level
Name the error each line would raise for L = [10, 20, 30]: (a) L[3] (b) L.remove(40) (c) L.index('10') (d) [].pop()
Try it first, then show the solutionSolution
- (a) Index 3 does not exist: IndexError.
- (b) 40 not in the list: ValueError.
- (c) '10' (a string) is not the integer 10: ValueError.
- (d) pop from an empty list: IndexError.
Answer: (a) IndexError (b) ValueError (c) ValueError (d) IndexError
Example 8: Mean and items above the mean · 3 marks · Short answerHarder exam level
For the rainfall list [12.5, 0.0, 7.5, 30.0, 18.0, 4.0, 12.0] (mm, one week), print the mean (rounded to 2 places), the wettest day number (1-7) and the number of days above the mean.
Try it first, then show the solutionSolution
R = [12.5, 0.0, 7.5, 30.0, 18.0, 4.0, 12.0] mean = sum(R) / len(R) print(round(mean, 2)) print(R.index(max(R)) + 1) c = 0 for r in R: if r > mean: c += 1 print(c)- Sum 84.0 / 7 = 12.0; max 30.0 at index 3 → day 4; above 12.0: 12.5, 30.0, 18.0 → 3.
Answer: 12.0
4
3
Case-study practice (Section E style)
Read the situation, then answer every part. In a school exam set on the board pattern this is a 4-mark question split into 1 + 1 + 1 + 1 marks.
Library waiting list
Suppose the school library keeps a waiting list for a popular book as a Python list of roll numbers in the order students asked: wait = [104, 117, 109, 121]. When the book is returned, the first student on the list gets it. Students can also cancel, and a student with a medical certificate may be placed second in the line.
(i) · 1 mark
Which method gives the book to the first student and also tells you who it is?
Answer
Answer: wait.pop(0), which removes and returns 104.
pop with an index returns the removed item.
(ii) · 1 mark
Student 109 cancels. Which method removes the student by roll number?
Answer
Answer: wait.remove(109).
remove works by value, pop by position.
(iii) · 1 mark
Student 130 with a medical certificate must be placed second. Show the list after the three operations.
Answer
Answer: After pop(0): [117, 109, 121]; after remove(109): [117, 121]; after insert(1, 130): [117, 130, 121].
insert(1, x) puts x at index 1.
(iv) · 1 mark
How would you check, before adding a new request, that a student is not already waiting, and find how many are ahead of student 121?
Answer
Answer: if roll not in wait: wait.append(roll). Students ahead of 121: wait.index(121), which is 2.
in prevents duplicates; index counts the items before it.
Where the marks are
How a typical answer is split into step marks. Show every step: a right final answer alone rarely earns full marks.
Differentiate between append() and extend() with an example. [2 marks] (2 marks)
| Step | Marks |
|---|---|
| append(x) adds its argument as a single item at the end: [1, 2].append([3, 4]) → [1, 2, [3, 4]] | 1 |
| extend(seq) adds each item of the sequence at the end: [1, 2].extend([3, 4]) → [1, 2, 3, 4] | 1 |
Write a program to find the largest and smallest numbers in a list without using max() or min(). [3 marks] (3 marks)
| Step | Marks |
|---|---|
| Initialise big = small = L[0] | 1 |
| Loop over the items comparing with big and small and updating them | 1.5 |
| Print both results | 0.5 |
Write a program to input n numbers into a list and then (i) print the mean, (ii) search for a key using linear search and print its position or 'Not found', and (iii) print the frequency of each distinct element. [5 marks] (5 marks)
| Step | Marks |
|---|---|
| Input n and build the list with a loop and append(int(input())) | 1 |
| (i) mean = sum(L) / len(L) (or by a loop) | 0.5 |
| (ii) Loop comparing each item with the key; break on a match; report position i + 1 or 'Not found' | 1.5 |
| (iii) For each item not already reported, print it with L.count(item) | 1.5 |
| Correct output formatting | 0.5 |
Where students lose marks in Lists
The slips examiners see most often, and what to write instead.
Mistake: Writing L = L.sort()
sort() sorts in place and returns None, so L becomes None.
Wrong working
L = [3, 1, 2]
L = L.sort()
print(L) → NoneRight working
L.sort()
print(L) → [1, 2, 3] (or L = sorted(L))Do this: Call in-place methods on their own line.
Usually costs: 1 mark
Mistake: Using append to add several items
append adds its argument as one item, nesting a list.
Wrong working
L = [1]; L.append([2, 3]) → [1, 2, 3]
Right working
L.append([2, 3]) → [1, [2, 3]]; L.extend([2, 3]) → [1, 2, 3]
Do this: Use extend (or +=) for several items.
Usually costs: 1 mark
Mistake: Passing an index to remove()
remove takes a value, not a position.
Wrong working
L = [10, 20, 30]; L.remove(0) → removes 10
Right working
L.remove(0) → ValueError (0 is not in L); use L.pop(0) or del L[0]
Do this: Position → pop or del; value → remove.
Usually costs: 1 mark
Mistake: Assuming B = A copies the list
Both names refer to the same list.
Wrong working
B = A; B[0] = 9; A is unchanged
Right working
B = A; B[0] = 9; A[0] is also 9. Use B = A[:] to copy.
Do this: Copy with [:], list() or copy().
Usually costs: 1 mark
Mistake: Removing items from a list while looping over it
Items shift left and the loop skips some of them.
Wrong working
L = [2, 4, 5, 6]
for x in L:
if x % 2 == 0: L.remove(x)
# L becomes [4, 5]Right working
L = [x for x in L if x % 2 != 0] or build a new list in a loop → [5]
Do this: Build a new list instead of removing during the loop.
Usually costs: 1-2 marks
NCERT exercise guide: Lists
What each exercise in the NCERT chapter tests, how to approach it, and a question of the same kind solved step by step. Questions here are written in our own words.
NCERT Chapter 9 exercise: outputs of list operations and methods
What it tests: Results of slicing, +, *, in and of methods such as append, extend, insert, pop, remove, sort and reverse on given lists.
How to approach it: Track the list after every statement; remember which methods return None, which return a value (pop, index, count) and which build a new list (+, slices, sorted).
Same kind as the 'what will be the output' questions
Give the output:
nums = [7, 3, 9, 3]
nums.extend([1, 2])
nums.insert(-1, 8)
print(nums)
print(nums.pop(2), nums.index(3), nums.count(3))
print(nums[::-2])Show the solutionSolution
- extend → [7, 3, 9, 3, 1, 2]. insert(-1, 8) puts 8 before the last item → [7, 3, 9, 3, 1, 8, 2].
- pop(2) returns 9 → [7, 3, 3, 1, 8, 2]; first 3 at index 1; 3 occurs twice.
- Every second item from the end: 2, 1, 3.
Answer: [7, 3, 9, 3, 1, 8, 2]
9 1 2
[2, 1, 3]
NCERT Chapter 9 exercise: list programs
What it tests: Programs that create lists from input, find statistics, search, count, and change lists.
How to approach it: Build the list with append in a loop; use a separate result list instead of deleting during traversal.
Same kind as the 'separate even and odd numbers' program
Write a program that splits [15, 22, 37, 40, 51, 68] into a list of even and a list of odd numbers and prints how many of each.
Show the solutionSolution
L = [15, 22, 37, 40, 51, 68] even, odd = [], [] for x in L: if x % 2 == 0: even.append(x) else: odd.append(x) print(even, len(even)) print(odd, len(odd))
Answer: [22, 40, 68] 3
[15, 37, 51] 3
Practice questions on Lists
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 · MCQExam level
What will L = [1, 2, 3]; L.append([4]); print(len(L)) print? (a) 3 (b) 4 (c) 5 (d) Error
Hint
One item added.
Answer
(b) 4
Q2 · 1 mark · Very short answerHarder exam level
Give the output: L = [5, 3, 8]; print(sorted(L), L, L.sort())
Hint
Arguments are evaluated left to right.
Answer
[3, 5, 8] [3, 5, 8] None. All three arguments are evaluated before anything is printed; L.sort() sorts L in place and returns None, so the second item already shows the sorted list.
Q3 · 2 marks · Short answerHarder exam level
Predict the output:
L = [10, 20, 30, 40, 50] L[1:3] = [25] print(L, L[-2:], 30 in L)Hint
Two items replaced by one.
Answer
[10, 25, 40, 50] [40, 50] False
Q4 · 2 marks · Short answerExam level
Write the difference between remove() and pop() with one example each.
Hint
Value or index? What is returned?
Answer
remove(x) deletes the first occurrence of the value x and returns None: [1, 2, 1].remove(1) → [2, 1]. pop(i) deletes the item at index i (default last) and returns it: [1, 2, 3].pop() returns 3, leaving [1, 2].
Q5 · 2 marks · Short answerExam level
Write a program to create a list of the squares of the numbers 1 to 10 and print the sum of those squares that are even.
Hint
Even squares come from even numbers.
Answer
sq = []
for i in range(1, 11):
sq.append(i * i)
s = 0
for x in sq:
if x % 2 == 0:
s += x
print(sq, s)
# s = 4 + 16 + 36 + 64 + 100 = 220Q6 · 3 marks · Short answerHOTS / competency
Predict the output:
A = [[1, 2], [3, 4]] B = A[:] B[0] = [9, 9] B[1][0] = 7 print(A) print(B)Hint
A[:] copies the outer list only.
Answer
[[1, 2], [7, 4]]
[[9, 9], [7, 4]]
(Replacing B[0] does not affect A, but B[1] is the same inner list as A[1], so changing B[1][0] shows in A too.)Q7 · 1 mark · MCQHarder exam level
Assertion (A): After L2 = L1, changing L2[0] also changes L1[0]. Reason (R): Assignment of a list to another name creates an alias, not a copy. Choose (a) both true, R explains A (b) both true, R does not explain A (c) A true, R false (d) A false, R true.
Hint
Same object?
Answer
(a)
Q8 · 3 marks · Short answerHarder exam level
Write a linear search program that prints all positions (from 1) where 5 occurs in [5, 1, 5, 7, 5] and prints 'Not found' if it never occurs.
Hint
Do not break; keep a flag.
Answer
L = [5, 1, 5, 7, 5]
found = False
for i in range(len(L)):
if L[i] == 5:
print(i + 1, end=' ')
found = True
if not found:
print('Not found')
Output: 1 3 5Q9 · 3 marks · Short answerHOTS / competency
Why does this code not remove all the zeros? L = [0, 0, 1, 0]; for x in L: if x == 0: L.remove(x). Give the final L and a correct method.
Hint
Items shift while the loop index moves on.
Answer
Removing an item shifts the rest left, so the loop skips the next item. Final L is [1, 0]. Correct: build a new list: L = [x for x in L if x != 0], or use while 0 in L: L.remove(0).
Q10 · 2 marks · Short answerHarder exam level
Give the output: print([1, 2] * 2 + [3], max(['apple', 'Banana', 'cherry']), sum([1.5, 2.5]))
Hint
Strings compare by character codes.
Answer
[1, 2, 1, 2, 3] cherry 4.0
Q11 · 3 marks · Short answerHOTS / competency
Write a program to input 5 marks into a list and print the marks in descending order along with the average of the top three.
Hint
sorted(..., reverse=True)[:3].
Answer
M = []
for i in range(5):
M.append(float(input()))
D = sorted(M, reverse=True)
print(D)
print(sum(D[:3]) / 3)Q12 · 1 mark · Very short answerExam level
What does list('2027') give, and what is its count('2')?
Hint
One item per character.
Answer
['2', '0', '2', '7']; count('2') is 2.
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.Are lists mutable?Show answer
Yes.
2.What does [0] * 4 give?Show answer
[0, 0, 0, 0].
3.What does pop() with no argument remove?Show answer
The last item, which it returns.
4.What does L.index(x) raise if x is absent?Show answer
ValueError.
5.What does sorted() return?Show answer
A new sorted list.
6.For M = [[1, 2], [3, 4]], what is M[1][0]?Show answer
3.
7.Which methods add items to a list?Show answer
append(), extend() and insert().
8.What is the output of print([1, 2].append(3))?Show answer
None.
Best order to study it
- Creating lists, list(), indexing, len().
- Mutability: item and slice assignment, del.
- Operators: +, *, in, slicing, comparisons.
- Traversal by item and by index.
- Methods: append, extend, insert, remove, pop, count, index, reverse, sort; sorted, min, max, sum.
- Nested lists and copying (aliasing).
- Programs: max/min/mean, linear search, frequency.
Quick revision checklist
The night before the exam: can you do each of these without looking?
- List: mutable ordered sequence in [ ]; any types; nested allowed.
- + makes a new list; * repeats; in checks items.
- append(x) one item; extend(seq) many; insert(i, x).
- remove(value), pop(index) returns item, del L[i].
- count, index (ValueError if absent), reverse, sort in place (None).
- sorted(L) new list; min, max, sum, len.
- B = A aliases; copy with A[:], list(A) or A.copy().
- M[i][j]: row i, column j; nested loops to traverse.
Lists: frequently asked questions
Is 'list as an argument to a function' in the Class 11 syllabus?
No. NCERT section 9.7 passes lists to user-defined functions, which CBSE moves to Class XII. You may still use built-in functions such as len(), sorted(), min() and sum() on lists.
What is the difference between del, remove() and pop()?
del L[i] is a statement that deletes by index (or a slice) and returns nothing. remove(x) deletes the first item equal to x and returns None. pop(i) deletes by index and returns the deleted item; with no index it removes the last item.
Can a list hold items of different types, and can such a list be sorted?
A list can hold any mix of types. But sort() and sorted() need items that can be compared, so a list such as [3, 'a'] raises a TypeError when sorted.
Does L += [x] create a new list?
No. For lists, += extends the same list in place (like extend), while L = L + [x] builds a new list and rebinds L. The difference shows when another name is an alias of L.
How do I count the frequency of every element without repeating values?
Loop through the list and keep a second list of values already reported; count each value only the first time you meet it. A dictionary (next chapter) makes this even easier.
Based on: CBSE Computer Science (083) syllabus, Class XI 2026-27; NCERT Computer Science, Textbook for Class XI, Chapter 9 Lists (Reprint 2026-27)