Skip to main content
Chapter 9 of 11
NCERT Solutions

Lists

Nagaland Board · Class 11 · Computer Science

NCERT Solutions for Lists — Nagaland Board Class 11 Computer Science.

45 questions22 flashcards5 concepts

Interactive on Super Tutor

Studying Lists? Get the full interactive chapter.

Quizzes, flashcards, AI doubt-solver and a step-by-step study plan — built for ncert solutions and more.

1,000+ Class 11 students started this chapter today

22 Questions Solved · 2 Sections

EXERCISE

1(i)What will be the output of the following statements?
list1 = [12,32,65,26,80,10]
list1.sort()
print(list1)
Show solution
Given: A list `list1 = [12,32,65,26,80,10]`

Concept: `list1.sort()` sorts the list in-place in ascending order and modifies the original list.

Working:
- Original list: `[12, 32, 65, 26, 80, 10]`
- After `list1.sort()`: elements are arranged in ascending order → `[10, 12, 26, 32, 65, 80]`
- `print(list1)` prints the modified list.

Output:
```
[10, 12, 26, 32, 65, 80]
```
1(ii)What will be the output of the following statements?
list1 = [12,32,65,26,80,10]
sorted(list1)
print(list1)
Show solution
Given: A list `list1 = [12,32,65,26,80,10]`

Concept: `sorted(list1)` returns a new sorted list but does not modify the original list. The result is not stored in any variable, so `list1` remains unchanged.

Working:
- `sorted(list1)` creates a new sorted list `[10, 12, 26, 32, 65, 80]` but it is discarded since it is not assigned to any variable.
- `list1` still holds its original values.
- `print(list1)` prints the original unmodified list.

Output:
```
[12, 32, 65, 26, 80, 10]
```
1(iii)What will be the output of the following statements?
list1 = [1,2,3,4,5,6,7,8,9,10]
list1[::-2]
list1[:3] + list1[3:]
Show solution
Given: `list1 = [1,2,3,4,5,6,7,8,9,10]`

Concept: Slicing creates a new list but does not modify the original. Since the results are not printed or assigned, there is no output from these statements.

Working:
- `list1[::-2]` → traverses from end to start with step 2-2, giving `[10, 8, 6, 4, 2]`. But this is not printed or stored.
- `list1[:3] + list1[3:]` → `[1,2,3] + [4,5,6,7,8,9,10]` = `[1,2,3,4,5,6,7,8,9,10]`. But this is also not printed or stored.

Output:
```
(No output — neither expression is printed)
```
1(iv)What will be the output of the following statements?
list1 = [1,2,3,4,5]
list1[len(list1)-1]
Show solution
Given: `list1 = [1,2,3,4,5]`

Concept: `len(list1)` returns 5. So `list1[len(list1)-1]` = `list1[4]` which is the last element. However, since this expression is not passed to `print()`, there is no output.

Working:
- `len(list1)` = 55
- `list1[5 - 1]` = `list1[4]` = 55
- The value 55 is computed but not printed.

Output:
```
(No output — the expression is not printed)
```

Note: If it were `print(list1[len(list1)-1])`, the output would be `5`.
2Consider the following list myList. What will be the elements of myList after the following two operations:
myList = [10,20,30,40]
i. myList.append([50,60])
ii. myList.extend([80,90])
Show solution
Given: `myList = [10, 20, 30, 40]`

Concept:
- `append(x)` adds `x` as a single element (even if `x` is a list) at the end.
- `extend(iterable)` adds each element of the iterable individually at the end.

Working:

i. After `myList.append([50,60])`:
- `[50, 60]` is added as a single element (a nested list).
- `myList` becomes: `[10, 20, 30, 40, [50, 60]]`

ii. After `myList.extend([80,90])` (applied on the result of step i):
- `80` and `90` are added individually.
- `myList` becomes: `[10, 20, 30, 40, [50, 60], 80, 90]`

Final Answer:
```
After append: [10, 20, 30, 40, [50, 60]]
After extend: [10, 20, 30, 40, [50, 60], 80, 90]
```
3What will be the output of the following code segment:
myList = [1,2,3,4,5,6,7,8,9,10]
for i in range(0,len(myList)):
if i%2 == 0:
print(myList[i])
Show solution
Given: `myList = [1,2,3,4,5,6,7,8,9,10]`

Concept: The loop iterates over indices ii from 00 to 99. The condition `i % 2 == 0` is true for even indices: 0,2,4,6,80, 2, 4, 6, 8.

Working:

| Index ii | i%2==0i \% 2 == 0? | `myList[i]` printed |
|-----------|----------------|---------------------|
| 0 | Yes | 1 |
| 1 | No | — |
| 2 | Yes | 3 |
| 3 | No | — |
| 4 | Yes | 5 |
| 5 | No | — |
| 6 | Yes | 7 |
| 7 | No | — |
| 8 | Yes | 9 |
| 9 | No | — |

Output:
```
1
3
5
7
9
```
4(a)What will be the output of the following code segment:
myList = [1,2,3,4,5,6,7,8,9,10]
del myList[3:]
print(myList)
Show solution
Given: `myList = [1,2,3,4,5,6,7,8,9,10]`

Concept: `del myList[3:]` deletes all elements from index 33 to the end of the list.

Working:
- Indices 33 to 99 correspond to elements 4,5,6,7,8,9,104, 5, 6, 7, 8, 9, 10.
- After deletion, only elements at indices 0,1,20, 1, 2 remain: 1,2,31, 2, 3.

Output:
```
[1, 2, 3]
```
4(b)What will be the output of the following code segment:
myList = [1,2,3,4,5,6,7,8,9,10]
del myList[:5]
print(myList)
Show solution
Given: `myList = [1,2,3,4,5,6,7,8,9,10]`

Concept: `del myList[:5]` deletes all elements from the beginning up to (but not including) index 55.

Working:
- Indices 00 to 44 correspond to elements 1,2,3,4,51, 2, 3, 4, 5.
- After deletion, elements at indices 55 to 99 remain: 6,7,8,9,106, 7, 8, 9, 10.

Output:
```
[6, 7, 8, 9, 10]
```
4(c)What will be the output of the following code segment:
myList = [1,2,3,4,5,6,7,8,9,10]
del myList[:2]
print(myList)
Show solution
Given: `myList = [1,2,3,4,5,6,7,8,9,10]`

Concept: `del myList[:2]` deletes elements from the beginning up to (but not including) index 22.

Working:
- Indices 00 and 11 correspond to elements 11 and 22.
- After deletion, elements at indices 22 to 99 remain: 3,4,5,6,7,8,9,103, 4, 5, 6, 7, 8, 9, 10.

Output:
```
[3, 4, 5, 6, 7, 8, 9, 10]
```
5Differentiate between append() and extend() functions of list.Show solution
Concept: Both `append()` and `extend()` are used to add elements to a list, but they work differently.

| Feature | `append(x)` | `extend(iterable)` |
|---|---|---|
| Purpose | Adds `x` as a single element at the end | Adds each element of the iterable individually at the end |
| Argument | Any object (integer, string, list, etc.) | Must be an iterable (list, tuple, string, etc.) |
| Effect on length | Length increases by 1 | Length increases by the number of elements in the iterable |
| Nested list | If a list is passed, it becomes a nested list | If a list is passed, its elements are added individually |

Example:
```python
list1 = [1, 2, 3]
list1.append([4, 5])
print(list1) # Output: [1, 2, 3, [4, 5]]

list2 = [1, 2, 3]
list2.extend([4, 5])
print(list2) # Output: [1, 2, 3, 4, 5]
```

Conclusion: `append()` adds the argument as one element, while `extend()` unpacks the iterable and adds each element separately.
6Consider a list: list1 = [6,7,8,9]
What is the difference between the following operations on list1:
a. list1 * 2
b. list1 *= 2
c. list1 = list1 * 2
Show solution
Given: `list1 = [6, 7, 8, 9]`

**a. `list1 * 2`
-
Concept:** The `*` operator creates and returns a new list by repeating `list1` twice. The original `list1` is not modified.
- Result: A new list `[6, 7, 8, 9, 6, 7, 8, 9]` is created but since it is not assigned, `list1` remains `[6, 7, 8, 9]`.

**b. `list1 *= 2`
-
Concept: This is an in-place repetition. It modifies `list1` directly (same object in memory) by repeating its elements twice.
-
Result: `list1` becomes `[6, 7, 8, 9, 6, 7, 8, 9]`. The same list object is updated.

c. `list1 = list1 * 2`
-
Concept:** `list1 * 2` creates a new list `[6, 7, 8, 9, 6, 7, 8, 9]`, and then `list1` is reassigned to point to this new list object.
- Result: `list1` now refers to a new list `[6, 7, 8, 9, 6, 7, 8, 9]`.

Summary of Differences:

| Operation | Modifies original? | Creates new list? | `list1` after operation |
|---|---|---|---|
| `list1 * 2` | No | Yes (discarded) | `[6,7,8,9]` |
| `list1 *= 2` | Yes (in-place) | No | `[6,7,8,9,6,7,8,9]` |
| `list1 = list1 * 2` | No | Yes (reassigned) | `[6,7,8,9,6,7,8,9]` |
7The record of a student is stored in: stRecord = ['Raman','A-36',[56,98,99,72,69], 78.8]
Write Python statements to retrieve:
a) Percentage of the student
b) Marks in the fifth subject
c) Maximum marks of the student
d) Roll no. of the student
e) Change the name of the student from 'Raman' to 'Raghav'
Show solution
Given: `stRecord = ['Raman', 'A-36', [56, 98, 99, 72, 69], 78.8]`

Structure of the list:
- Index 0 → Name: `'Raman'`
- Index 1 → Roll No.: `'A-36'`
- Index 2 → Marks list: `[56, 98, 99, 72, 69]`
- Index 3 → Percentage: `78.8`

---

a) Percentage of the student:
```python
print(stRecord[3])
```
Output: `78.8`

---

b) Marks in the fifth subject:
- The marks list is at index 2. The fifth subject is at index 4 of the inner list.
```python
print(stRecord[2][4])
```
Output: `69`

---

c) Maximum marks of the student:
- Use `max()` on the marks list at index 2.
```python
print(max(stRecord[2]))
```
Output: `99`

---

d) Roll no. of the student:
```python
print(stRecord[1])
```
Output: `A-36`

---

e) Change the name from 'Raman' to 'Raghav':
- Lists are mutable, so we can directly assign a new value at index 0.
```python
stRecord[0] = 'Raghav'
print(stRecord)
```
Output: `['Raghav', 'A-36', [56, 98, 99, 72, 69], 78.8]`

PROGRAMMING PROBLEMS

1Write a program to find the number of times an element occurs in the list.Show solution
Concept: Use the built-in `count()` method of lists which returns the number of times a specified element appears in the list.

Program:
```python
# Program to find the number of times an element occurs in a list

# Input: Read the list
n = int(input("Enter the number of elements: "))
myList = []
for i in range(n):
element = int(input("Enter element: "))
myList.append(element)

print("List:", myList)

# Input: Element to search
item = int(input("Enter the element to count: "))

# Count occurrences using count()
count = myList.count(item)

print("The element", item, "occurs", count, "time(s) in the list.")
```

Sample Run:
```
Enter the number of elements: 6
Enter element: 1
Enter element: 2
Enter element: 3
Enter element: 2
Enter element: 1
Enter element: 2
List: [1, 2, 3, 2, 1, 2]
Enter the element to count: 2
The element 2 occurs 3 time(s) in the list.
```
2Write a program to read a list of n integers (positive as well as negative). Create two new lists, one having all positive numbers and the other having all negative numbers from the given list. Print all three lists.Show solution
Concept: Traverse the original list and check each element. If it is greater than 0, add to the positive list; if less than 0, add to the negative list.

Program:
```python
# Program to separate positive and negative numbers into two lists

n = int(input("Enter the number of elements: "))
originalList = []

for i in range(n):
num = int(input("Enter element: "))
originalList.append(num)

positiveList = []
negativeList = []

for num in originalList:
if num > 0:
positiveList.append(num)
elif num < 0:
negativeList.append(num)

print("Original List: ", originalList)
print("Positive Numbers:", positiveList)
print("Negative Numbers:", negativeList)
```

Sample Run:
```
Enter the number of elements: 7
Enter element: 3
Enter element: -5
Enter element: 8
Enter element: -2
Enter element: 0
Enter element: 7
Enter element: -9
Original List: [3, -5, 8, -2, 0, 7, -9]
Positive Numbers: [3, 8, 7]
Negative Numbers: [-5, -2, -9]
```
3Write a function that returns the largest element of the list passed as parameter.Show solution
Concept: Traverse the list and keep track of the maximum element found so far. Return it at the end. (We avoid using the built-in `max()` to demonstrate the logic.)

Program:
```python
# Function to return the largest element of a list

def findLargest(lst):
"""Returns the largest element in the list."""
largest = lst[0] # Assume first element is largest
for i in range(1, len(lst)):
if lst[i] > largest:
largest = lst[i] # Update if a larger element is found
return largest

# Main program
n = int(input("Enter the number of elements: "))
myList = []
for i in range(n):
num = int(input("Enter element: "))
myList.append(num)

result = findLargest(myList)
print("The largest element is:", result)
```

Sample Run:
```
Enter the number of elements: 5
Enter element: 34
Enter element: 12
Enter element: 78
Enter element: 45
Enter element: 23
The largest element is: 78
```
4Write a function to return the second largest number from a list of numbers.Show solution
Concept: Sort the list in descending order and return the element at index 1. Alternatively, find the largest, remove it, and find the largest again. We must handle duplicates (e.g., if the largest appears multiple times).

Program:
```python
# Function to return the second largest number from a list

def secondLargest(lst):
"""Returns the second largest unique element in the list."""
# Create a sorted list of unique elements in descending order
uniqueSorted = sorted(set(lst), reverse=True)
if len(uniqueSorted) < 2:
return None # No second largest exists
return uniqueSorted[1]

# Main program
n = int(input("Enter the number of elements: "))
myList = []
for i in range(n):
num = int(input("Enter element: "))
myList.append(num)

result = secondLargest(myList)
if result is not None:
print("The second largest element is:", result)
else:
print("Second largest does not exist.")
```

Sample Run:
```
Enter the number of elements: 5
Enter element: 10
Enter element: 45
Enter element: 23
Enter element: 45
Enter element: 8
The second largest element is: 23
```
5Write a program to read a list of n integers and find their median.
Note: The median value of a list of values is the middle one when they are arranged in order. If there are two middle values then take their average.
Show solution
Concept:
- Sort the list.
- If the number of elements nn is odd, the median is the middle element at index n//2n // 2.
- If nn is even, the median is the average of the two middle elements at indices n//21n//2 - 1 and n//2n//2.

Program:
```python
# Program to find the median of a list of n integers

def findMedian(lst):
"""Returns the median of the list."""
lst.sort() # Sort the list in ascending order
n = len(lst)
if n % 2 != 0: # Odd number of elements
median = lst[n // 2]
else: # Even number of elements
mid1 = lst[n // 2 - 1]
mid2 = lst[n // 2]
median = (mid1 + mid2) / 2
return median

# Main program
n = int(input("Enter the number of elements: "))
myList = []
for i in range(n):
num = int(input("Enter element: "))
myList.append(num)

result = findMedian(myList)
print("Sorted List:", myList)
print("Median:", result)
```

Sample Run 1 (Odd n):
```
Enter the number of elements: 5
Enter element: 7
Enter element: 2
Enter element: 9
Enter element: 4
Enter element: 1
Sorted List: [1, 2, 4, 7, 9]
Median: 4
```

Sample Run 2 (Even n):
```
Enter the number of elements: 4
Enter element: 3
Enter element: 8
Enter element: 1
Enter element: 6
Sorted List: [1, 3, 6, 8]
Median: 4.5
```
6Write a program to read a list of elements. Modify this list so that it does not contain any duplicate elements, i.e., all elements occurring multiple times in the list should appear only once.Show solution
Concept: Traverse the list and build a new list that contains only the first occurrence of each element. We check if the element is already present before adding it.

Program:
```python
# Program to remove duplicate elements from a list

n = int(input("Enter the number of elements: "))
myList = []
for i in range(n):
num = int(input("Enter element: "))
myList.append(num)

print("Original List:", myList)

# Remove duplicates
newList = []
for item in myList:
if item not in newList:
newList.append(item)

# Update the original list
myList = newList

print("List after removing duplicates:", myList)
```

Sample Run:
```
Enter the number of elements: 8
Enter element: 1
Enter element: 2
Enter element: 3
Enter element: 2
Enter element: 4
Enter element: 1
Enter element: 5
Enter element: 3
Original List: [1, 2, 3, 2, 4, 1, 5, 3]
List after removing duplicates: [1, 2, 3, 4, 5]
```
7Write a program to read a list of elements. Input an element from the user that has to be inserted in the list. Also input the position at which it is to be inserted. Write a user defined function to insert the element at the desired position in the list.Show solution
Concept: Use the `insert(index, element)` method of lists inside a user-defined function. The position entered by the user is 1-based (natural), so we convert it to 0-based index.

Program:
```python
# Program to insert an element at a desired position in a list

def insertElement(lst, pos, elem):
"""Inserts elem at position pos (1-based) in lst."""
if pos < 1 or pos > len(lst) + 1:
print("Invalid position!")
else:
lst.insert(pos - 1, elem) # Convert to 0-based index
return lst

# Main program
n = int(input("Enter the number of elements: "))
myList = []
for i in range(n):
num = int(input("Enter element: "))
myList.append(num)

print("Original List:", myList)

elem = int(input("Enter the element to insert: "))
pos = int(input("Enter the position (1-based) to insert at: "))

myList = insertElement(myList, pos, elem)
print("List after insertion:", myList)
```

Sample Run:
```
Enter the number of elements: 4
Enter element: 10
Enter element: 20
Enter element: 40
Enter element: 50
Original List: [10, 20, 40, 50]
Enter the element to insert: 30
Enter the position (1-based) to insert at: 3
List after insertion: [10, 20, 30, 40, 50]
```
8(a)Write a program to read elements of a list. The program should ask for the position of the element to be deleted from the list. Write a function to delete the element at the desired position in the list.Show solution
Concept: Use `pop(index)` to delete the element at a given index. The user provides a 1-based position which is converted to a 0-based index.

Program:
```python
# Program to delete an element at a given position from a list

def deleteByPosition(lst, pos):
"""Deletes element at position pos (1-based) from lst."""
if pos < 1 or pos > len(lst):
print("Invalid position!")
else:
removed = lst.pop(pos - 1) # Convert to 0-based index
print("Deleted element:", removed)
return lst

# Main program
n = int(input("Enter the number of elements: "))
myList = []
for i in range(n):
num = int(input("Enter element: "))
myList.append(num)

print("Original List:", myList)

pos = int(input("Enter the position (1-based) of element to delete: "))
myList = deleteByPosition(myList, pos)
print("List after deletion:", myList)
```

Sample Run:
```
Enter the number of elements: 5
Enter element: 10
Enter element: 20
Enter element: 30
Enter element: 40
Enter element: 50
Original List: [10, 20, 30, 40, 50]
Enter the position (1-based) of element to delete: 3
Deleted element: 30
List after deletion: [10, 20, 40, 50]
```
8(b)The program should ask for the value of the element to be deleted from the list. Write a function to delete the element of this value from the list.Show solution
Concept: Use `remove(value)` to delete the first occurrence of the specified value. If the value is not present, handle the error gracefully.

Program:
```python
# Program to delete an element by value from a list

def deleteByValue(lst, val):
"""Deletes the first occurrence of val from lst."""
if val in lst:
lst.remove(val)
print("Element", val, "deleted successfully.")
else:
print("Element", val, "not found in the list.")
return lst

# Main program
n = int(input("Enter the number of elements: "))
myList = []
for i in range(n):
num = int(input("Enter element: "))
myList.append(num)

print("Original List:", myList)

val = int(input("Enter the value of element to delete: "))
myList = deleteByValue(myList, val)
print("List after deletion:", myList)
```

Sample Run:
```
Enter the number of elements: 5
Enter element: 10
Enter element: 20
Enter element: 30
Enter element: 20
Enter element: 50
Original List: [10, 20, 30, 20, 50]
Enter the value of element to delete: 20
Element 20 deleted successfully.
List after deletion: [10, 30, 20, 50]
```
9Read a list of n elements. Pass this list to a function which reverses this list in-place without creating a new list.Show solution
Concept: To reverse a list in-place without creating a new list, we swap elements from both ends moving towards the centre. We use two pointers: `left` starting at index 00 and `right` starting at index n1n-1, swapping and moving them towards each other.

Program:
```python
# Program to reverse a list in-place without creating a new list

def reverseList(lst):
"""Reverses the list in-place using two-pointer swapping."""
left = 0
right = len(lst) - 1
while left < right:
# Swap elements at left and right indices
lst[left], lst[right] = lst[right], lst[left]
left += 1
right -= 1
# No return needed as list is modified in-place

# Main program
n = int(input("Enter the number of elements: "))
myList = []
for i in range(n):
num = int(input("Enter element: "))
myList.append(num)

print("Original List:", myList)

reverseList(myList) # List is modified in-place

print("Reversed List:", myList)
```

Sample Run:
```
Enter the number of elements: 6
Enter element: 10
Enter element: 20
Enter element: 30
Enter element: 40
Enter element: 50
Enter element: 60
Original List: [10, 20, 30, 40, 50, 60]
Reversed List: [60, 50, 40, 30, 20, 10]
```

Note: The function modifies the original list directly (in-place) because lists are passed by reference in Python. No new list is created.

Stuck on a step?

Ask Super Tutor AI to explain any solution on this page in a simpler way — free, 24x7.

Ask a Doubt Free

Frequently Asked Questions

What are the important topics in Lists for Nagaland Board Class 11 Computer Science?
Lists covers several key topics that are frequently asked in Nagaland Board Class 11 board exams. Focus on the core concepts listed on this page and practise related questions to build confidence.
How to score full marks in Lists — Nagaland Board Class 11 Computer Science?
Understand the core concepts first, then work through the 45 practice questions available for this chapter. Revise formulas and definitions regularly, and use flashcards for quick recall before the exam.
Where can I get free NCERT Solutions for Lists Class 11 Computer Science?
This page has free step-by-step NCERT Solutions for every exercise question in Lists (Nagaland Board Class 11 Computer Science) — written the way examiners award marks: given, formula, working, answer.

Sources & Official References

Content is aligned to the official syllabus. Refer to the board website for the latest curriculum.

For serious students

Get the full Lists chapter — for free.

Quizzes, flashcards, AI doubt-solver and a step-by-step study plan for Nagaland Board Class 11 Computer Science.