Class 11 Computer Science Chapter 9 Revision Summary Strictly NCERT

REVISION SUMMARY: Lists (NCERT Class 11 Computer Science)

1. Chapter at a Glance

  • A list is an ordered sequence that is mutable and can contain elements of mixed data types (integer, float, string, tuple or even another list).
  • Elements are enclosed in square brackets [] and separated by commas; indexing starts at 0 (supports both positive and negative indices).
  • Lists support four basic operations: concatenation (+), repetition (*), membership (in / not in) and slicing.
  • A list can be traversed using a for loop (with or without range(len())) or a while loop.
  • Built-in functions and methods (len(), append(), extend(), insert(), pop(), remove(), sort(), sorted(), etc.) allow creation, modification and manipulation of lists.
  • Nested lists are created when a list appears as an element of another list; elements are accessed using double indices list[i][j].
  • Assignment list2 = list1 creates an alias (same object); distinct copies are made by slicing, list() or copy.copy().
  • When a list is passed as an argument to a function, the reference is passed, so modifications inside the function are reflected in the original list unless the parameter is reassigned a new list.

2. Key Terms and Definitions

  • list: an ordered sequence which is mutable and made up of one or more elements.
  • mutable: the contents of the list can be changed after it has been created.
  • nested list: when a list appears as an element of another list.
  • concatenation: joining two or more lists using the + operator.
  • repetition: replicating a list using the * operator.
  • membership: checking presence of an element using in (returns True if present) or not in.
  • slicing: extracting a sub-list using the syntax list[start:end:step].
  • aliasing: assigning one list variable to another (list2 = list1) so both refer to the same list object.
  • cloning / copying: creating a distinct copy of a list (using slicing, list() or copy.copy()) so that changes to one do not affect the other.

3. Syntax and Constructs

```python

Creating a list

list1 = [2, 4, 6, 8, 10, 12] list2 = list() # empty list list3 = list("aeiou") # from sequence

Concatenation and repetition

list1 + list2 list1 * 3

Membership

'Red' in list1 'Cyan' not in list1

Slicing

list1[2:6] list1[::2] list1[::-1]

Traversal

for item in list1: print(item) for i in range(len(list1)): print(list1[i]) i = 0 while i < len(list1): print(list1[i]) i += 1 ```

Methods & Built-in Functions (general form + example)

python len(list1) # returns length list1.append(50) # appends single element at end list1.extend([40,50]) # appends each element of argument list list1.insert(2, 25) # inserts at index list1.count(10) # returns occurrences list1.index(20) # returns first index or ValueError list1.remove(30) # removes first occurrence or ValueError list1.pop(3) # removes & returns element at index (default last) list1.reverse() # reverses in-place list1.sort() # sorts in-place (ascending); sort(reverse=True) for descending sorted(list1) # returns new sorted list min(list1), max(list1), sum(list1)

4. Algorithms and Worked Logic

List Traversal (for / while)
- Initialise list → use for item in list1 or for i in range(len(list1)) or while i < len(list1) with i += 1.

Linear Search (Program 9-5 style)
1. Accept list and search value.
2. Loop from 0 to len(list)-1.
3. If list[i] == num, return i.
4. If loop ends, return None.

Copying a List (three distinct methods)
- newList = oldList[:] (slicing)
- newList = list(oldList)
- import copy; newList = copy.copy(oldList)

List as Function Argument

  • Pass list reference → modifications inside function affect original list.
  • If parameter is reassigned a new list inside function, changes stay local.

5. Common Errors and Exam Pitfalls

  • IndexError: list index out of range when index exceeds length.
  • TypeError: can only concatenate list (not "str") to list when using + with non-list.
  • ValueError from index() or remove() when element is absent.
  • Confusing append([50,60]) (adds list as single element) with extend([50,60]) (adds each element).
  • Using sort() (in-place, returns None) instead of sorted() (returns new list) or vice-versa.
  • Assuming list2 = list1 creates an independent copy (it creates an alias).
  • Forgetting that list1[n-1] or list1[-n] gives last/first element when using len().
  • Not handling the case when an element occurs multiple times (remove() deletes only first occurrence).
  • In menu-driven programs, missing boundary checks before pop(i) or insert(pos, elem).

A study aid reviewed by GFIS faculty — always verify with your textbook and teacher.