Core9X
Log inSign up

MBOSE Class XI Informatics Practices · Chapter 4

Working with Lists and Dictionaries

Opening soon

How to store many values in a list, how to change and search it, and how a dictionary stores key : value pairs so that data can be found by name.

17 lessons · 69 practice questions

See classes open nowLog inMBOSE Class XI opens to new students soon.

What this chapter covers

  • Lists: list operations (creating, initializing, traversing and manipulating lists), list methods and built-in functions len(), list(), append(), insert(), count(), index(), remove(), pop(), reverse(), sort(), min(), max(), sum()
  • Dictionary: concept of key-value pair, creating, initializing, traversing, updating and deleting elements, dictionary methods and built-in functions dict(), len(), keys(), values(), items(), update(), del, clear()

Key terms

List

Ordered, mutable sequence in square brackets

Index

Position of an item, starting from 0

Traversal

Visiting each item in turn

In place

Changing the same list without making a new one

Dictionary

Mapping of unique keys to values

Key

Unique, immutable name used to find a value

Value

The data stored against a key

View

The result of keys(), values() or items()

Important questions with answers

10 of the 69 questions on this chapter, solved.

  1. Question 1 · Multiple choice · 1 mark

    Which of these is a list?

    • (a) (1, 2)
    • (b) "12"
    • (c) {1, 2}
    • (d) [1, 2]

    Answer: (d) [1, 2]

    A list is written in square brackets.

  2. Question 2 · Multiple choice · 1 mark

    Lists differ from strings because lists are

    • (a) immutable
    • (b) mutable
    • (c) unordered
    • (d) of fixed size

    Answer: (b) mutable

    Their items can be changed.

  3. Question 3 · Multiple choice · 1 mark

    sum([1, 2, 3, 4]) is

    • (a) 10
    • (b) 24
    • (c) 4
    • (d) error

    Answer: (a) 10

    1 + 2 + 3 + 4.

  4. Question 4 · Multiple choice · 1 mark

    "a" in {"a": 1} is

    • (a) error
    • (b) False
    • (c) None
    • (d) True

    Answer: (d) True

    The key a is present.

  5. 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.

  6. Question 6 · Short answer · 1 mark

    What is a list?

    Answer

    An ordered, mutable collection of items in square brackets.

  7. 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] = 10 gives [10, 2].

  8. 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), append and print (1).

  9. Question 9 · Long answer · 5 marks

    Explain the operations on lists (concatenation, repetition, membership, slicing) with examples and outputs.

    Answer

    Section 1.2.

  10. 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.5.

Study the whole chapter

17 step-by-step lessons, all 69 practice questions with hints, flashcards and mock tests for MBOSE Class XI Informatics Practices.

See classes open nowLog inMBOSE Class XI opens to new students soon.
Working with Lists and Dictionaries: MBOSE Class 11 Informatics Practices notes, important questions and answers · Core9X