MBOSE Class XI Computer Science · Chapter 9
Lists
Opening soonHow a list stores many values in order, how to change it, and how to search, sort and summarise the data in it.
15 lessons · 69 practice questions
What this chapter covers
- Lists: introduction, indexing, list operations (concatenation, repetition, membership and slicing), traversing a list using loops, built-in functions and methods
len(),list(),append(),extend(),insert(),count(),index(),remove(),pop(),reverse(),sort(),sorted(),min(),max(),sum() - Nested lists
- Suggested programs: maximum, minimum and mean of the numbers in a list, linear search, frequency of elements
Key terms
- List
Ordered, mutable sequence in square brackets
- Nested list
A list that has a list as an item
- Mutable
Can be changed after creation
- Traversal
Visiting each item in turn
- In place
Changing the same list without making a new one
- Linear search
Checking items one by one from the start
- Frequency
Number of times an item occurs
- Median
Middle value of the sorted data
- Alias
A second name for the same list (
b = a)
Important questions with answers
10 of the 69 questions on this chapter, solved.
Question 1 · Multiple choice · 1 mark
Which of these is a list?
- (a) (1, 2)
- (b) {1, 2}
- (c) [1, 2]
- (d) "12"
Answer: (c) [1, 2]
A list is written in square brackets.
Question 2 · Multiple choice · 1 mark
Which of these raises a TypeError?
- (a) [1] + [2]
- (b) [1] + 2
- (c) [1] * 2
- (d) 2 in [1, 2]
Answer: (b) [1] + 2
A list and an integer cannot be concatenated.
Question 3 · Multiple choice · 1 mark
[5, 3, 4].index(3)is- (a) 0
- (b) 1
- (c) 2
- (d) 3
Answer: (b) 1
3 is at index 1.
Question 4 · Multiple choice · 1 mark
After
L = [1, 2, 3, 4]anddel L[1], L is- (a) [1, 2, 4]
- (b) [2, 3, 4]
- (c) [1, 3, 4]
- (d) [1, 2, 3]
Answer: (c) [1, 3, 4]
The item at index 1 is deleted.
Question 5 · Assertion and reason · 1 mark
Assertion (A): A list is mutable.
Reason (R): The items of a list can be changed after the list is created.
- (a) Both A and R are true, and R is the correct explanation of A.
- (b) Both A and R are true, but R is not the correct explanation of A.
- (c) A is true, but R is false.
- (d) A is false, but R is true.
Answer: (a) Both A and R are true, and R is the correct explanation of A.
R explains A.
Question 6 · Short answer · 1 mark
What is a list?
Answer
An ordered, mutable collection of items in square brackets.
Question 7 · Short answer · 2 marks
Why is a list called mutable? Give an example.
Answer
Its items can be changed after creation:
L = [1, 2]; L[0] = 10gives[10, 2].Question 8 · Short answer · 3 marks
Write a program to create a list of the squares of the numbers 1 to 5.
squares = [] for i in range(1, 6): squares.append(i * i) print(squares)Output:
[1, 4, 9, 16, 25]Answer
Empty list (1), loop (1),
appendand print (1).Question 9 · Long answer · 5 marks
Explain the operations on lists (concatenation, repetition, membership, slicing) with examples and outputs.
Answer
Section 1.2.
Question 10 · Long answer · 5 marks
Write programs for the maximum, minimum and mean of a list, and for linear search.
Answer
Sections 1.3 and 1.6.
Study the whole chapter
15 step-by-step lessons, all 69 practice questions with hints, flashcards and mock tests for MBOSE Class XI Computer Science.