Circle of Learning Logo CIRCLE OF LEARNING Excellence in Education
CBSE Class 11 · Computer Science Chapter 6 Session 2026-27

Lists in Python Formulas & Cheat Sheet

Complete chapter-wise reference, step-by-step formula explanations, structured table, and board exam trap warnings.

Core Concepts & Theoretical Foundations

  • List Definition: An ordered, mutable, heterogeneous sequence of elements enclosed in square brackets ([...]).
  • List Mutability: Unlike strings and tuples, lists are mutable. Individual items can be modified, replaced, added, or deleted in-place: lst[0] = 99.
  • Indexing & Slicing: Supports two-way indexing (0 to n-1 and -1 to -n) and slicing lst[start : stop : step]. Modifying slices: lst[1:3] = [10, 20] replaces multiple elements in-place.
  • List Operations: Concatenation (+ combines lists); Repetition (* replicates elements); Membership (in, not in); Traversal (for item in lst:).
  • Adding Elements: .append(x) (adds single element x at the end); .extend(iterable) (appends all elements of iterable to the end); .insert(i, x) (inserts element x at index i).
  • Removing Elements: .pop() (removes and returns last element); .pop(i) (removes and returns element at index i); .remove(x) (removes first occurrence of value x; raises ValueError if not found); .clear() (removes all elements); del lst[i] (deletes item or slice).
  • Built-in List Methods: len(L), L.count(x), L.index(x), L.sort() (sorts in-place, returns None), L.sort(reverse=True), sorted(L) (returns new sorted list, leaves original unchanged), L.reverse() (reverses in-place), min(L), max(L), sum(L).
  • Aliasing vs Cloning: L2 = L1 creates an alias (both variables reference the same list object). L2 = L1.copy() or L2 = L1[:] creates a shallow copy (independent list object).

Chapter Formulas & Equations (10 entries)

# Topic / Formula Name Mathematical Form & Equation Conditions, Meaning & Board Tips
1 List Append vs Extend Behavior
append([a,b])  ⟹  L=[…,[a,b]],extend([a,b])  ⟹  L=[…,a,b]\text{append}([a, b]) \implies L = [\dots, [a, b]], \quad \text{extend}([a, b]) \implies L = [\dots, a, b]

.append() adds its argument as a single object, while .extend() iterates over the collection and adds each element individually.

2 Aliasing vs Shallow Copy Identity
(b=a)  ⟹  id(a)==id(b),(b=a[:])  ⟹  id(a)≠id(b)∧a==b(b = a) \implies \text{id}(a) == \text{id}(b), \quad (b = a[:]) \implies \text{id}(a) \neq \text{id}(b) \wedge a == b

Modifying an aliased list changes both variables; modifying a cloned slice leaves the original list unaffected.

3 In-Place Sort vs Global sorted()
L.sort()  ⟹  L modified, returns None;M=sorted(L)  ⟹  L preservedL.\text{sort}() \implies L \text{ modified, returns None}; \quad M = \text{sorted}(L) \implies L \text{ preserved}

Common bug: assigning L = L.sort() overwrites L with None!

4 List Pop vs Remove Distinction
pop(i)→Removes at index i,remove(x)→Removes first x∈L\text{pop}(i) \rightarrow \text{Removes at index } i, \quad \text{remove}(x) \rightarrow \text{Removes first } x \in L

.pop() works with index positions (defaults to last element); .remove() searches for matching values.

5 Linear Search Algorithm Complexity
Tlinear(N)=O(N)[Checks each element sequentially until match]T_{\text{linear}}(N) = \mathcal{O}(N) \quad [\text{Checks each element sequentially until match}]

Standard search algorithm across unsorted lists; time taken grows linearly with list length.

6 Nested List 2D Matrix Indexing
Mi,j=matrix[i][j](0≤i<rows, 0≤j<cols)M_{i, j} = \text{matrix}[i][j] \quad (0 \le i < \text{rows}, \, 0 \le j < \text{cols})

Lists of lists represent 2D matrices, tables, and grids in Python algorithms.

7 List Slice Replacement Equation
L[i:j]=[v1,v2,…,vk]  ⟹  Δlen(L)=k−(j−i)L[i:j] = [v_1, v_2, \dots, v_k] \implies \Delta \text{len}(L) = k - (j - i)

Replacing a slice with an iterable of different length changes the total size of the list in-place.

8 List Comprehension Mathematical Syntax
{f(x)∣x∈S, P(x)}=[f(x) for x in S if P(x)]\{ f(x) \mid x \in S, \, P(x) \} = [f(x) \text{ for } x \text{ in } S \text{ if } P(x)]

Compact, elegant, and computationally efficient Python construct mirroring mathematical set-builder notation.

9 Binary Search Prerequisite & Complexity
Tbinary(N)=O(log⁡2N)[Requires L to be strictly sorted]T_{\text{binary}}(N) = \mathcal{O}(\log_2 N) \quad [\text{Requires } L \text{ to be strictly sorted}]

Significantly faster than linear search for large datasets; checks middle element and discards half the list.

10 Sum and Average of Numeric List
xˉ=∑i=0n−1L[i]n=sum(L)len(L)\bar{x} = \frac{\sum_{i=0}^{n-1} L[i]}{n} = \frac{\text{sum}(L)}{\text{len}(L)}

Standard statistical calculation across lists of integers or floating-point values.

CBSE Board Exam Tips & Frequent Pitfalls

  • Never assign L = L.sort()! .sort() modifies the list in-place and returns None, so L will become None.
  • Remember that L.append([3, 4]) adds the list as a single element [..., [3, 4]], whereas L.extend([3, 4]) adds 3 and 4 as individual elements.
  • When removing items from a list in a loop, iterate over a copy L[:], otherwise skipping elements occurs due to shifting indices.

Step-by-Step Worked Board Exam Examples

Example 1: What will be the output of the following code? a = [10, 20, 30] b = a c = a.copy() a.append(40) b[0] = 99 print('a:', a) print('b:', b) print('c:', c)

b = a creates an alias pointing to the same memory object.

c = a.copy() creates an independent clone containing [10, 20, 30].

a.append(40) mutates the shared list to [10, 20, 30, 40].

b[0] = 99 mutates the first element of the shared list to 99.

Since a and b reference the same object: a is [99, 20, 30, 40], b is [99, 20, 30, 40].

c was cloned before any modifications, so c remains [10, 20, 30].

Ans: a: [99, 20, 30, 40] b: [99, 20, 30, 40] c: [10, 20, 30]

Example 2: Given L = [12, 18, 25, 30, 35], write a single-line list comprehension to extract all numbers divisible by 3.

Use list comprehension syntax: [x for x in iterable if condition].

Condition for divisibility by 3: x % 3 == 0.

Expression: div_by_3 = [x for x in L if x % 3 == 0].

Evaluation: 12 (yes), 18 (yes), 25 (no), 30 (yes), 35 (no) -> [12, 18, 30].

Ans: [x for x in L if x % 3 == 0] which yields [12, 18, 30].

Common Mistakes to Avoid in Exam

  • Calling .remove(x) when element x is not in the list raises a ValueError. Always check if x in L: first.
  • Confusing sort() and reverse(). sort() orders items by magnitude, while reverse() simply flips the existing order backwards.
  • Thinking L * 3 creates deep copies of inner lists. If L = [[0]], then L * 3 creates three references to the exact same inner list.

Target Practice Questions

Q1. What will len([1, [2, 3], 4]) return?

Correct Answer: Returns 3 (the nested list [2, 3] is counted as 1 element).

Q2. What is the output of [1, 2] + [3, 4] in Python?

Correct Answer: [1, 2, 3, 4] (concatenation).

Q3. How do you reverse a list L in-place?

Correct Answer: Using L.reverse().

Frequently Asked Questions

Q. What is the difference between append() and extend()?

append() adds its argument as a single element at the end of the list; extend() iterates over an iterable and appends each element individually.

Q. What is the time complexity of searching an element in an unsorted list?

Linear search has a time complexity of O(N), where N is the number of elements in the list.

Q. How do you delete an element at index 2 from list L?

Using del L[2] or L.pop(2).

Q. What does L.index(x) return?

Returns the index of the first occurrence of item x in the list, or raises a ValueError if x is not found.

← View All 9 Chapters in Class 11 Computer Science Formula Book