Follow Us
माध्यम चुनें / Select Medium:
Eng (English) Hindi (हिन्दी)
CBSE • कक्षा XI • Computer Science • अध्याय 9
अनुमानित समय: 45 Mins
प्रगति: अध्ययनरत

सूचियां (Lists in Python)

In CBSE Class 11 Computer Science, "Lists" provides an exhaustive, industry-grade master guide to mutable sequence processing in Python. This comprehensive chapter covers list memory allocation, dynamic resizing, heterogeneous element storage, indexing, slicing, sequence operators, in-place mutability mechanics, aliasing vs shallow vs deep copying, 2D nested list matrix algorithms, and the complete taxonomy of list manipulation methods (`append()`, `extend()`, `insert()`, `pop()`, `remove()`, `sort()`, `reverse()`, `clear()`) aligned with the 2026–27 CBSE curriculum.

How Do Operating Systems and Databases Manage Growing Collections of Data in Memory?

Imagine an online shopping cart or a playlist on Spotify. You add items, remove tracks, reorder songs, and filter by artist. The collection grows and shrinks dynamically during runtime. How does a computer manage an ordered sequence of data whose size changes constantly without having to reallocate the entire hard drive? In Python, the List is the supreme workhorse data structure. Unlike static arrays in C or Java that require fixed sizes at declaration, Python lists are dynamic, mutable arrays that store references to any data type—integers, strings, floating points, and even other nested lists. How do lists balance memory speed and mutability, and how does list aliasing cause some of the most baffling bugs in software engineering? This chapter masters mutable sequence engineering.

यह अध्याय क्यों महत्वपूर्ण है

Lists are the most widely used collection data structure in Python. Every web application, database pipeline, and data science toolkit relies on lists to accumulate, sort, filter, and transform datasets. Understanding the difference between in-place mutation methods (like `list.sort()`) and new-object creation (like `sorted(list)`), as well as the distinction between aliasing (`b = a`) and cloning (`b = a.copy()`), is essential to writing bug-free, high-performance algorithms.

अध्ययन से पूर्व (आवश्यक ज्ञान)

  • Dual indexing (positive and negative) and slicing syntax from strings.
  • Concept of mutability vs immutability from Chapter 5.
  • Flow of control: `for` loops and conditional statements.

इस अध्याय के लक्ष्य

  • Create and initialize empty, populated, and nested heterogeneous lists.
  • Demonstrate list mutability by updating, replacing, and appending elements in-place.
  • Execute dual indexing and advanced slicing on lists (`lst[start:stop:step]`).
  • Compare `append()` (single element addition) with `extend()` (iterable concatenation).
  • Contrast `pop()` (index-based deletion returning value) with `remove()` (value-based first-occurrence deletion).
  • Differentiate in-place `lst.sort()` from built-in function `sorted(lst)`.
  • Analyze the danger of List Aliasing (`b = a`) and implement shallow copy (`a.copy()`, `a[:]`).
  • Traverse and manipulate 2D nested lists (matrices) using nested loops.

अध्याय रूपरेखा एवं प्रगति

1 1. List Architecture & Mutability M...
2 2. Comprehensive List Manipulation...
3 3. List Aliasing vs. Shallow Clonin...
4 4. 2D Lists & Matrix Algorithms

सम्पूर्ण सैद्धांतिक एवं वैचारिक अध्ययन

1. List Architecture & Mutability Mechanics

Understand

A List in Python is an ordered, mutable, heterogeneous sequence of elements enclosed in square brackets (`[...]`):

  • Heterogeneous: Can contain mixed data types: `items = [101, "Aarav", 98.5, True, [1, 2]]`.
  • Mutable: Elements can be altered, appended, inserted, or removed in-place without changing the list's physical memory address (`id()` remains constant).
In-Place Item Assignment Proof:
nums = [10, 20, 30]
print("Initial id:", id(nums))   # e.g., 0x7ffd10
nums[1] = 99                     # In-place assignment!
print(nums)                      # [10, 99, 30]
print("Post-update id:", id(nums)) # EXACT SAME ID! Memory block was mutated in-place.

2. Comprehensive List Manipulation Methods

Understand & Reference
Method SignatureActionExample Code & Result
`lst.append(item)`Appends `item` as a single element to the end.`[1, 2].append([3, 4])` → `[1, 2, [3, 4]]`
`lst.extend(iterable)`Unpacks `iterable` and appends its elements individually.`[1, 2].extend([3, 4])` → `[1, 2, 3, 4]`
`lst.insert(index, item)`Inserts `item` at `index`, shifting subsequent items right.`['a', 'c'].insert(1, 'b')` → `['a', 'b', 'c']`
`lst.pop([index])`Removes and returns item at `index` (default last item).`x = [10, 20].pop()` → `x = 20`, list is `[10]`
`lst.remove(value)`Deletes first occurrence of `value`; raises `ValueError` if absent.`[5, 1, 5].remove(5)` → `[1, 5]`
`lst.clear()`Removes all items, leaving an empty list `[]`.`nums.clear()` → `[]`
`lst.sort([reverse=True])`Sorts list in-place; returns `None`!`[3, 1, 2].sort()` → list is `[1, 2, 3]`
`sorted(iterable)`Built-in function returning a brand-new sorted list.`orig = [3, 1]; new_l = sorted(orig)` (orig unchanged)
`lst.reverse()`Reverses elements in-place.`[1, 2, 3].reverse()` → `[3, 2, 1]`

3. List Aliasing vs. Shallow Cloning vs. Deep Copy

Understand & Deep Danger

One of the most dangerous traps in Python is confusing Aliasing with Cloning (Copying):

A. List Aliasing (Reference Copying)

When you assign `b = a`, Python does NOT copy the list. It merely creates a second variable name that points to the exact same list in heap memory:

a = [1, 2, 3]
b = a              # ALIASING: 'b' and 'a' point to the exact same list object!
b.append(999)
print(a)           # Outputs: [1, 2, 3, 999] (Modifying 'b' modified 'a'!)
B. Shallow Copy (Cloning)

To create an independent clone of the list so that modifications to one do not affect the other, use `copy()` or full slice `[:]`:

a = [1, 2, 3]
b = a.copy()       # or b = a[:] (Independent clone)
b.append(999)
print(a)           # Outputs: [1, 2, 3] (Original 'a' is preserved!)

4. 2D Lists & Matrix Algorithms

Understand

A 2D List (Matrix) is a list whose elements are themselves lists:

matrix = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
]
# Access element at row 1, col 2:
print(matrix[1][2]) # Outputs 6

# Matrix Traversal:
for row in matrix:
    for val in row:
        print(f"{val:2d}", end=" ")
    print()

प्रोग्रामिंग सिंटेक्स, स्टेटमेंट्स एवं भाषा अनुवादक नियम

List Concatenation vs Extend
$$a + b \text{ creates new list; } a.\text{extend}(b) \text{ mutates } a \text{ in-place}$$
Time and memory trade-offs in sequence growth.
List Shallow Copy
$$b = a.copy() \iff b = a[:]$$
Creates an independent top-level list object.

List Memory Layout & Aliasing Architecture

Python List Memory Architecture: Aliasing vs Cloning Aliasing: b = a (Same Object) a b List Object [1, 2, 3] id: 0x7fa10 (Ref Count: 2) Modifying b directly alters a! Cloning: b = a.copy() (Distinct Objects) a b List Object [1, 2, 3] id: 0x88b01 (Ref Count: 1) List Object [1, 2, 3] id: 0x99c02 (Ref Count: 1) Safe! Modifications to b never affect a.

अध्याय का सार संक्षेप एवं 10 मुख्य निष्कर्ष

मुख्य बिंदु 1
A list is an ordered, mutable sequence of heterogeneous elements enclosed in square brackets `[...]`.
मुख्य बिंदु 2
List elements can be modified in-place using index assignment (`lst[i] = val`).
मुख्य बिंदु 3
`append(x)` appends a single item to the end; `extend(iterable)` iterates through the collection and appends elements individually.
मुख्य बिंदु 4
`insert(i, x)` inserts element `x` at index `i`, shifting existing elements rightward.
मुख्य बिंदु 5
`pop(i)` removes and returns the element at index `i`; `remove(val)` deletes the first occurrence of `val`.
मुख्य बिंदु 6
`sort()` sorts a list in-place and returns `None`; `sorted()` returns a brand-new sorted list object.
मुख्य बिंदु 7
List Aliasing occurs when two variable names point to the exact same list object (`b = a`); modifying one modifies both.
मुख्य बिंदु 8
Cloning (`b = a.copy()` or `b = a[:]`) creates an independent shallow copy in memory.
मुख्य बिंदु 9
A 2D list (matrix) is indexed via `matrix[row][col]`.
मुख्य बिंदु 10
List slicing `lst[start:stop:step]` allows extraction and batch sub-sequence replacements.

स्व-मूल्यांकन अभ्यास (Check Your Understanding)

मूल वैचारिक स्पष्टता की जांच के लिए नैदानिक प्रश्न। पहले स्वयं हल करें, फिर उत्तर देखें।

1
Predict the output of the following list operations:
a = [1, 2, 3]
b = [4, 5]
a.append(b)
print("append:", a)
x = [1, 2, 3]
x.extend(b)
print("extend:", x)
उत्तर एवं व्याख्या देखें
उत्तर: Output line 1: `append: [1, 2, 3, [4, 5]]`
Output line 2: `extend: [1, 2, 3, 4, 5]`
Explanation: `append()` treats its argument as a single object, nesting the entire list `[4, 5]` inside `a`. `extend()` unpacks the elements of `b` and appends each individual integer separately to `x`.
append adds the list as a nested sub-element; extend unpacks and appends individual items.
2
What is the critical difference between `lst.sort()` and `sorted(lst)`? Demonstrate with code.
उत्तर एवं व्याख्या देखें
उत्तर:

lst.sort() is a list method that sorts the elements in-place directly inside the original list object and returns None. The original list is permanently reordered.
sorted(lst) is a built-in function that leaves the original list completely unmodified and returns a brand-new sorted list in memory.
Code:
nums = [3, 1, 2]
res = nums.sort()
print(nums, res) # [1, 2, 3] None
orig = [5, 2]
new_l = sorted(orig)
print(orig, new_l) # [5, 2] [2, 5]


sort() mutates in-place returning None; sorted() returns a new sorted list.
3
Explain the concept of List Aliasing. What output does the following code produce?
x = [10, 20, 30]
y = x
y[0] = 999
print(x)
उत्तर एवं व्याख्या देखें
उत्तर:

Output: [999, 20, 30]
Explanation: The statement y = x does NOT create a copy of the list; it creates an alias (both x and y reference the exact same list object at the same heap address). Modifying y[0] directly mutates the shared list object, so printing x reflects the change 999.


y = x binds two variable names to the same list object; mutating y mutates x.
4
How do you create an independent copy of a list to prevent aliasing bugs?
उत्तर एवं व्याख्या देखें
उत्तर: You can create an independent shallow copy using either the `copy()` method or full slicing `[:]`:
y = x.copy() or y = x[:]
This allocates a brand-new list object in memory so modifications to `y` will never affect `x`.
Use .copy() or [:] to clone the list.
5
Differentiate between `pop()` and `remove()` methods with respect to arguments, return values, and error conditions.
उत्तर एवं व्याख्या देखें
उत्तर:

• pop([index]): Takes an index as argument (defaults to -1, the last item), removes that item, and returns it. Raises IndexError if the index is invalid.
• remove(value): Takes a value as argument, finds its first occurrence, removes it, and returns None. Raises ValueError if the value is not in the list.


pop removes by index and returns the item; remove deletes by value and returns None.
6
Write a Python program to find the second largest number in a list of numbers without using built-in `sort()` or `sorted()`.
उत्तर एवं व्याख्या देखें
उत्तर:
numbers = [12, 45, 2, 41, 31, 10, 8, 45]
largest = second = float('-inf')
for n in numbers:
    if n > largest:
        second = largest
        largest = n
    elif n > second and n != largest:
        second = n
print("Second largest:", second)  # Outputs: 41

Track largest and second largest in a single pass through the list.
7
Given a 2D matrix `m = [[1, 2], [3, 4], [5, 6]]`, write code to calculate the sum of all elements.
उत्तर एवं व्याख्या देखें
उत्तर:
m = [[1, 2], [3, 4], [5, 6]]
total = 0
for row in m:
    for val in row:
        total += val
print("Total sum:", total)  # Outputs: 21

Use nested for loops to iterate through each row and each value.
8
What is the output of `lst = [1, 2, 3] * 3` followed by `lst[0] = 99`? Explain.
उत्तर एवं व्याख्या देखें
उत्तर: Output: `[99, 2, 3, 1, 2, 3, 1, 2, 3]`
Explanation: The replication operator `* 3` concatenates three copies of the sequence into a flat list of 9 elements: `[1, 2, 3, 1, 2, 3, 1, 2, 3]`. Assigning `lst[0] = 99` modifies only the element at index 0.
Replication creates a 9-element flat list; lst[0] updates only the first element.
अध्याय का अध्ययन पूर्ण हुआ?
अभ्यास के लिए तैयार?

ऑनलाइन CBT टेस्ट देकर तैयारी का मूल्यांकन करें

झारखण्ड बोर्ड परीक्षा पैटर्न पर आधारित बहुविकल्पीय प्रश्नों का ऑनलाइन टेस्ट दें। तुरंत परिणाम, समय विश्लेषण और प्रत्येक प्रश्न का विस्तृत हल प्राप्त करें।

AI अध्ययन मित्र

त्वरित शंका समाधान

सूचियां (Lists in Python) में कोई संदेह या प्रश्न है? हमारे AI अध्ययन मित्र से तुरंत समझें।