Skip to content
Computer ScienceCBSE Class 11 · Chapter 9

Tuples and Dictionaries Class 11: Operations, Methods and Programs in Python

Updated 14 October 2026 · Fact-checked

A tuple is an immutable ordered sequence written in round brackets; a dictionary is a mutable collection of key: value pairs in curly brackets. In CBSE Class 11 Computer Science you learn tuple operations, tuple assignment and nested tuples, dictionary access, changes and traversal, and the syllabus methods from count() and index() to get(), update(), pop(), popitem(), setdefault() and fromkeys().

What Tuples and Dictionaries is about

This chapter is part of Unit II, Computational Thinking and Programming - 1, which carries 45 of the 70 theory marks in the school annual exam. It completes Python's built-in collections: tuples (fixed sequences) and dictionaries (look-up by key).

The 2026-27 syllabus lists for tuples: introduction, indexing, operations (concatenation, repetition, membership, slicing), len(), tuple(), count(), index(), sorted(), min(), max(), sum(), tuple assignment, nested tuples, and programs for minimum, maximum, mean, linear search and frequency on a tuple. For dictionaries: introduction, accessing items by key, mutability (adding and modifying items), traversal, and len(), dict(), keys(), values(), items(), get(), update(), del, clear(), fromkeys(), copy(), pop(), popitem(), setdefault(), max(), min(), sorted(), with programs to count characters in a string using a dictionary and to store employee names and salaries.

All outputs below are from running the code in Python 3 (3.7 and later keep dictionary items in insertion order, which the outputs rely on).

Weightage: This chapter is part of Unit II, Computational Thinking and Programming - 1, which carries 45 of the 70 theory marks in the school annual exam together with Introduction to Problem Solving, Getting Started with Python, Flow of Control, Strings, Lists and Introduction to Python Modules.Source: CBSE Computer Science (083) syllabus 2026-27, Class XI distribution of marks, Unit II Computational Thinking and Programming - 1

Key concepts

Tuples: creation, indexing and immutability
NCERT section NCERT 10.1

A tuple is an ordered sequence of items, of any types, separated by commas and usually written in round brackets: t = (10, 'ten', 10.5). The comma makes the tuple, not the brackets: t = 1, 2, 3 is a tuple, but (5) is just the int 5, and a one-item tuple needs a trailing comma: (5,). () is the empty tuple; tuple(seq) converts a sequence: tuple('abc') = ('a', 'b', 'c').

Indexing and slicing work as for strings and lists (slices give new tuples). Tuples are immutable: t[0] = 1 raises TypeError, and there are no append or remove methods. But if a tuple contains a mutable item such as a list, that list itself can still be changed. Use a tuple for data that should not change (days of the week, coordinates, a date of birth); tuples can also be dictionary keys, lists cannot.

Worked example

Give type() of each: a = (7), b = (7,), c = 7, 8, d = ('7'). Then say what t = (1, [2, 3]); t[1].append(4); print(t) shows.

Try it first, then show the solutionSolution
  1. (7) is just 7 in brackets: int. (7,) is a tuple. 7, 8 is a tuple. ('7') is a str.
  2. t[1] is a list inside the tuple; appending changes the list, not which object the tuple holds.

Answer: int, tuple, tuple, str; t prints (1, [2, 3, 4]).

Tuple operations and functions
NCERT section NCERT 10.2, 10.3
  • Concatenation t1 + t2 gives a new tuple: (1, 2) + (3,) = (1, 2, 3). Adding a non-tuple, as in (1, 2) + 3, raises TypeError.
  • Repetition (0,) * 3 = (0, 0, 0).
  • Membership x in t / not in t.
  • Slicing t[1:3], t[::-1].

Methods and functions: len(t), tuple(seq), t.count(x) (occurrences), t.index(x) (first position; ValueError if absent), sorted(t) (returns a sorted list, not a tuple), min(t), max(t), sum(t) (numbers only). Because tuples are immutable, they have only the two methods count() and index().

Worked example

t = (4, 9, 2, 9, 7). Give t + (1,), t[1:4], t.count(9), t.index(9), sorted(t), max(t) - min(t), sum(t) / len(t).

Try it first, then show the solutionSolution
  1. (4, 9, 2, 9, 7, 1); slice (9, 2, 9).
  2. 9 occurs twice; first at index 1.
  3. sorted gives the list [2, 4, 7, 9, 9].
  4. 9 - 2 = 7; 31 / 5 = 6.2.

Answer: (4, 9, 2, 9, 7, 1), (9, 2, 9), 2, 1, [2, 4, 7, 9, 9], 7, 6.2

Tuple assignment and nested tuples
NCERT section NCERT 10.4, 10.5

Tuple assignment (unpacking) assigns the items of a tuple on the right to the names on the left, in order: (name, roll, marks) = ('Asha', 7, 91). The number of names must equal the number of items, or Python raises ValueError. The right side is evaluated completely first, which is why a, b = b, a swaps two values. The right side can be any expression giving a tuple, e.g. q, r = 17 // 5, 17 % 5.

A nested tuple has tuples as items: records = (('Asha', 91), ('Ravi', 78)). records[1][0] is 'Ravi'. Traverse with a loop, often unpacking each inner tuple: for name, m in records: ...

Worked example

Give the output:

x, y, z = 3, 'b', (5, 6)
p, q = z
print(x * y, p + q)
st = (('Neha', 82), ('Arjun', 95), ('Sara', 88))
for name, m in st:
    if m > 85:
        print(name, end=' ')
Try it first, then show the solutionSolution
  1. x = 3, y = 'b', z = (5, 6); unpacking z gives p = 5, q = 6.
  2. 3 * 'b' = 'bbb'; 5 + 6 = 11.
  3. Inner tuples unpacked: Arjun (95) and Sara (88) are above 85.

Answer: bbb 11
Arjun Sara

Tuple programs: statistics, linear search, frequency
NCERT section NCERT 10.6; syllabus suggested programs

Programs on tuples work like those on lists, using only reading operations: traverse with for, compare, count. Since a tuple cannot be changed, build any result (such as the list of values already counted) in a separate list. If input is needed, read the values into a list and convert with tuple() at the end.

Worked example

For temps = (31, 34, 29, 35, 34, 30, 34), print the mean (2 decimals), the minimum, the maximum and the frequency of 34, and search for 33.

Try it first, then show the solutionSolution
  1. temps = (31, 34, 29, 35, 34, 30, 34)
    print(round(sum(temps) / len(temps), 2), min(temps), max(temps))
    print(temps.count(34))
    key = 33
    for i in range(len(temps)):
        if temps[i] == key:
            print('Found at index', i)
            break
    else:
        print(key, 'not found')
  2. Sum 227 / 7 = 32.43. 34 appears three times. 33 is absent. (The else after a for loop runs only when the loop ends without break; a found flag works just as well.)

Answer: 32.43 29 35
3
33 not found

Dictionaries: creation and access by key
NCERT section NCERT 10.7, 10.9

A dictionary stores key: value pairs inside curly brackets: d = {'roll': 7, 'name': 'Asha', 'marks': 91}. It is a mapping: you look up a value by its key, not by position.

  • Keys must be unique and of an immutable type (str, int, float, tuple); a list as a key raises TypeError. If a key is repeated when the dictionary is written, the last value wins.
  • Values can be of any type and can repeat.
  • {} is an empty dictionary; dict() also makes one, e.g. dict(a=1, b=2) or dict([('a', 1), ('b', 2)]).
  • d[key] returns the value; a missing key raises KeyError. d.get(key) returns None (or a given default) instead of an error.
  • key in d checks keys only.

Worked example

d = {'apple': 40, 'mango': 60, 'kiwi': 25}. Give d['mango'], d.get('grape'), d.get('grape', 0), 'kiwi' in d, 25 in d, and what d['grape'] does.

Try it first, then show the solutionSolution
  1. 'mango' maps to 60.
  2. 'grape' is not a key: get gives None, or the default 0.
  3. 'kiwi' is a key: True. 25 is a value, not a key: False.
  4. Indexing with a missing key raises KeyError.

Answer: 60, None, 0, True, False; d['grape'] raises KeyError.

Dictionaries are mutable: adding, modifying, deleting
NCERT section NCERT 10.8, 10.11
  • Add a pair by assigning to a new key: d['pear'] = 50.
  • Modify by assigning to an existing key: d['apple'] = 45 (the old value is replaced).
  • del d[key] deletes a pair (KeyError if absent).
  • d.pop(key[, default]) removes the key and returns its value; with a default, a missing key returns the default instead of raising KeyError.
  • d.popitem() removes and returns the last inserted pair as a tuple (KeyError if the dictionary is empty).
  • d.clear() empties the dictionary (it still exists, as {}).
  • d.update(other) adds the pairs of another dictionary, overwriting values of keys that already exist.

Worked example

Give the output:

d = {'a': 1, 'b': 2}
d['c'] = 3
d['a'] = 10
d.update({'b': 20, 'd': 4})
print(d)
print(d.pop('c'), d.popitem(), d)
Try it first, then show the solutionSolution
  1. Add 'c', change 'a': {'a': 10, 'b': 2, 'c': 3}.
  2. update overwrites 'b' and adds 'd': {'a': 10, 'b': 20, 'c': 3, 'd': 4}.
  3. pop('c') returns 3; popitem() removes the last pair ('d', 4).

Answer: {'a': 10, 'b': 20, 'c': 3, 'd': 4}
3 ('d', 4) {'a': 10, 'b': 20}

Traversing a dictionary and keys(), values(), items()
NCERT section NCERT 10.10, 10.11

for k in d: loops over the keys; use d[k] for the value. The views:

  • d.keys(): all keys, e.g. dict_keys(['a', 'b'])
  • d.values(): all values
  • d.items(): all pairs as (key, value) tuples; for k, v in d.items(): unpacks each pair

Convert a view with list() when a list is needed. len(d) is the number of pairs. On a dictionary, max(d), min(d) and sorted(d) work on the keys; for values use max(d.values()) or sorted(d.values()).

Worked example

sal = {'Ravi': 42000, 'Meera': 55000, 'Joseph': 38000}. Print each name with salary, then the sorted names, the highest salary and who earns it.

Try it first, then show the solutionSolution
  1. sal = {'Ravi': 42000, 'Meera': 55000, 'Joseph': 38000}
    for name, s in sal.items():
        print(name, s)
    print(sorted(sal), max(sal))
    high = max(sal.values())
    for name in sal:
        if sal[name] == high:
            print(name, high)
  2. sorted(sal) and max(sal) use the keys (names); max(sal.values()) is 55000.

Answer: Ravi 42000
Meera 55000
Joseph 38000
['Joseph', 'Meera', 'Ravi'] Ravi
Meera 55000

fromkeys(), copy() and setdefault()
NCERT section NCERT 10.11
  • dict.fromkeys(keys[, value]) makes a new dictionary with the given keys, all with the same value (None if no value is given): dict.fromkeys(['a', 'b'], 0) = {'a': 0, 'b': 0}.
  • d.copy() returns a new dictionary with the same pairs (a shallow copy); changing the copy's pairs does not change d. In contrast, e = d makes an alias.
  • d.setdefault(key[, default]): if key exists, returns its value and changes nothing; if not, adds key with the default (None if not given) and returns the default. It is handy for counting and grouping.

Worked example

Give the output:

d = dict.fromkeys(['x', 'y'], 0)
e = d.copy()
e['x'] = 5
print(d, e)
print(d.setdefault('x', 9), d.setdefault('z', 9), d)
Try it first, then show the solutionSolution
  1. fromkeys gives {'x': 0, 'y': 0}; e is a separate copy, so only e changes.
  2. 'x' exists: setdefault returns 0 and changes nothing. 'z' is missing: added with 9, which is returned.

Answer: {'x': 0, 'y': 0} {'x': 5, 'y': 0}
0 9 {'x': 0, 'y': 0, 'z': 9}

Counting characters with a dictionary
NCERT section NCERT 10.12; syllabus suggested program

A dictionary is the natural tool for frequencies: each distinct item becomes a key and its count the value. The pattern is: if the key is already present, add 1; otherwise start it at 1. The same can be written as d[ch] = d.get(ch, 0) + 1. After the loop, traverse with items() to print the counts.

Worked example

Count how many times each character appears in 'banana' and print the dictionary and the most frequent character.

Try it first, then show the solutionSolution
  1. s = 'banana'
    freq = {}
    for ch in s:
        if ch in freq:
            freq[ch] += 1
        else:
            freq[ch] = 1
    print(freq)
    best = ''
    for ch in freq:
        if best == '' or freq[ch] > freq[best]:
            best = ch
    print(best, freq[best])
  2. Keys appear in the order first seen: b, a, n.

Answer: {'b': 1, 'a': 3, 'n': 2}
a 3

Tuples and Dictionaries in real life

Each concept, met in an everyday situation. Read the situation, answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.

Dictionary look-up

Suppose a school canteen app stores prices as {'idli': 30, 'dosa': 50, 'tea': 15} and a student orders 2 dosas and 1 tea.

Compute the bill using the dictionary.

Try it first, then show the solutionSolution
  1. bill = 2 * menu['dosa'] + 1 * menu['tea'].
  2. 2 × 50 + 15 = 115.

Answer: ₹115.

Memory hook: Look up by name, not by position.

Tuples for fixed data

Imagine an attendance app that stores the days a class meets as a tuple ('Mon', 'Wed', 'Fri') and the marks of each test in a list.

Why is a tuple suitable for the days and a list for the marks?

Try it first, then show the solutionSolution
  1. The meeting days are fixed; an immutable tuple prevents accidental changes.
  2. Test marks keep being added, so they need a mutable list with append().

Answer: Tuple for fixed data, list for data that grows or changes.

Memory hook: Fixed → tuple; changing → list.

Counting with a dictionary

Suppose the school election officer has a list of votes: ['Asha', 'Ravi', 'Asha', 'Neel', 'Asha', 'Ravi'].

How would a dictionary give each candidate's total, and who wins?

Try it first, then show the solutionSolution
  1. For each vote: count[name] = count.get(name, 0) + 1.
  2. Result {'Asha': 3, 'Ravi': 2, 'Neel': 1}.

Answer: Asha wins with 3 votes.

Memory hook: Key = item, value = how many.

Topics in this chapter

Tuples and Dictionaries: syntax and key facts

One-item tuple
(x,) is a tuple; (x) is just x
The comma makes the tuple.
Tuple methods
count(x), index(x); functions len, tuple, sorted (→ list), min, max, sum
No methods that change a tuple.
Dictionary access
d[k] (KeyError if missing); d.get(k, default); k in d checks keys
Keys unique and immutable.
Dictionary changes
  1. 1.d[k] = v (add or modify); del d[k]; pop(k)
  2. 2.value; popitem()
  3. 3.last pair; clear(); update(other)
update overwrites existing keys.
Views
keys(), values(), items() → (key, value) pairs
max/min/sorted on d work on keys.
Counting pattern
d[x] = d.get(x, 0) + 1
Or setdefault(x, 0) then d[x] += 1.

How the school exam asks Tuples and Dictionaries

The question patterns to expect, and the method that works for each.

Question typeHow it is askedMethod
Output of tuple operationsSlicing, +, *, count, index, sorted on a tuple; one-item tuples (1-2 marks).Remember sorted gives a list and (x) is not a tuple.
Tuple vs list / immutability"Differentiate between a list and a tuple"; why does t[0] = 5 fail? (2 marks)Mutability, brackets, methods available, use as dictionary keys.
Output of dictionary codeA dictionary changed by update, pop, popitem, setdefault, then printed (2-3 marks).Keep the pairs in insertion order after every statement; note return values.
Dictionary programsCount characters or words, employee or student records, search by key, highest value (3-5 marks).Build with d[k] = v in a loop; traverse with items(); use get() to avoid KeyError.
Error spottingKeyError, TypeError for a list key, ValueError in unpacking (1-2 marks).Name the error and give the corrected statement.

Tricks to remember Tuples and Dictionaries

Short memory aids. Say each one aloud once, then use it on a question the same day.

  • Comma, not bracket

    A tuple is born from a comma: (5,) yes, (5) no.

    Use it when: One-item tuple questions.

  • Tuple has two tools

    count and index are the only tuple methods: C-I.

    Use it when: Listing tuple methods.

  • get is gentle, [ ] is strict

    d.get(k) quietly gives None; d[k] shouts KeyError.

    Use it when: Missing-key questions.

  • pop gives the value, popitem gives the pair

    pop(key) → value; popitem() → (key, value) of the last item.

    Use it when: Return values.

  • Dictionary functions see keys

    max, min, sorted and in on a dictionary look only at keys.

    Use it when: Output questions.

Tuples and Dictionaries: exam-level solved questions

Ordered from exam level to HOTS. Cover the solution, write your own, then compare step by step.

Example 1: Unpacking and swapping · 2 marks · Short answerExam level

Give the output:

a, b, c = (1, 2, 3)
a, b, c = c, a, b
print(a, b, c)
q, r = divmod(29, 6)
print(q, r)
Try it first, then show the solutionSolution
  1. The right side (3, 1, 2) is built first, then assigned.
  2. divmod(29, 6) returns the tuple (4, 5): quotient and remainder.

Answer: 3 1 2
4 5

Example 2: Tuple errors · 2 marks · Short answerHarder exam level

Which lines raise errors, and which error? t = (2, 4, 6)
(a) t[1] = 5 (b) t = t + (8,) (c) t.append(10) (d) x, y = t (e) print(t[1:10])

Try it first, then show the solutionSolution
  1. (a) Item assignment on a tuple: TypeError.
  2. (b) Builds a new tuple and rebinds t: no error.
  3. (c) Tuples have no append: AttributeError.
  4. (d) 3 values into 2 names: ValueError.
  5. (e) Slicing never raises an error: (4, 6) (or (4, 6, 8) if (b) ran first).

Answer: (a) TypeError (c) AttributeError (d) ValueError; (b) and (e) run.

Example 3: Dictionary trace · 3 marks · Short answerHarder exam level

Give the output:

d = {'P': 3, 'C': 4, 'M': 5}
d.setdefault('B', 2)
d.setdefault('P', 9)
x = d.pop('C')
d['M'] += x
print(d)
print(sorted(d), max(d.values()), list(d.items())[0])
Try it first, then show the solutionSolution
  1. 'B' added with 2; 'P' exists, unchanged.
  2. pop('C') returns 4; M becomes 9.
  3. d = {'P': 3, 'M': 9, 'B': 2}; sorted keys ['B', 'M', 'P']; max value 9; first pair ('P', 3).

Answer: {'P': 3, 'M': 9, 'B': 2}
['B', 'M', 'P'] 9 ('P', 3)

Example 4: Word frequency · 3 marks · Short answerHarder exam level

Write a program that counts how many times each word occurs in 'the cat and the hat and the bat' and prints the words that occur more than once.

Try it first, then show the solutionSolution
  1. s = 'the cat and the hat and the bat'
    wc = {}
    for w in s.split():
        wc[w] = wc.get(w, 0) + 1
    print(wc)
    for w, c in wc.items():
        if c > 1:
            print(w, c)

Answer: {'the': 3, 'cat': 1, 'and': 2, 'hat': 1, 'bat': 1}
the 3
and 2

Example 5: Invert a dictionary · 3 marks · Short answerHOTS / competency

Grades are stored as {'Asha': 'A', 'Ravi': 'B', 'Neel': 'A', 'Sara': 'C'}. Build a dictionary that groups students by grade, e.g. {'A': ['Asha', 'Neel'], ...}, using setdefault().

Try it first, then show the solutionSolution
  1. g = {'Asha': 'A', 'Ravi': 'B', 'Neel': 'A', 'Sara': 'C'}
    by = {}
    for name, gr in g.items():
        by.setdefault(gr, []).append(name)
    print(by)
  2. setdefault returns the existing list for a grade, or adds an empty list the first time; append adds the name to it.

Answer: {'A': ['Asha', 'Neel'], 'B': ['Ravi'], 'C': ['Sara']}

Example 6: Employee salary dictionary · 3 marks · Short answerExam level

Create {'E01': 32000, 'E02': 47000, 'E03': 29000}. Increase E03's salary by 3000, add E04 with 41000, and print the total salary bill and the employees earning below the average.

Try it first, then show the solutionSolution
  1. emp = {'E01': 32000, 'E02': 47000, 'E03': 29000}
    emp['E03'] += 3000
    emp['E04'] = 41000
    total = sum(emp.values())
    avg = total / len(emp)
    print(total, avg)
    for k in emp:
        if emp[k] < avg:
            print(k, emp[k])
  2. Total 32000 + 47000 + 32000 + 41000 = 152000; average 38000.0.

Answer: 152000 38000.0
E01 32000
E03 32000

Example 7: Merging stock records · 3 marks · Short answerHOTS / competency

Suppose shop A has stock {'pen': 10, 'ink': 4} and shop B has {'ink': 6, 'clip': 20}. Explain why A.update(B) gives the wrong total for ink, and write a loop that adds the quantities instead.

Try it first, then show the solutionSolution
  1. update overwrites: A['ink'] would become 6, losing A's 4.
  2. A = {'pen': 10, 'ink': 4}
    B = {'ink': 6, 'clip': 20}
    for k, v in B.items():
        A[k] = A.get(k, 0) + v
    print(A)

Answer: {'pen': 10, 'ink': 10, 'clip': 20}

Example 8: Nested tuple search · 2 marks · Short answerHOTS / competency

cities = (('Delhi', 'DL'), ('Mumbai', 'MH'), ('Chennai', 'TN')). Write code that prints the state code of Mumbai, and turn the tuple into a dictionary in one step.

Try it first, then show the solutionSolution
  1. cities = (('Delhi', 'DL'), ('Mumbai', 'MH'), ('Chennai', 'TN'))
    for c, code in cities:
        if c == 'Mumbai':
            print(code)
    d = dict(cities)
    print(d['Chennai'])
  2. dict() accepts a sequence of (key, value) pairs.

Answer: MH
TN

Case-study practice (Section E style)

Read the situation, then answer every part. In a school exam set on the board pattern this is a 4-mark question split into 1 + 1 + 1 + 1 marks.

Class library tracker

Suppose a class keeps a dictionary books = {'B1': ('Wings of Fire', 'in'), 'B2': ('Godan', 'out'), 'B3': ('Gitanjali', 'in')}, where each value is a tuple (title, status).

  1. (i) · 1 mark

    Why is a tuple a suitable value here, and what must happen when B1 is issued?

    Answer

    Answer: The title and status form one fixed record. Since a tuple cannot be changed, issuing B1 means assigning a new tuple: books['B1'] = ('Wings of Fire', 'out').

    Replace the whole value; the key stays.

  2. (ii) · 1 mark

    Write code to print the titles of all books that are in.

    Answer

    Answer: for code, (title, status) in books.items():
    if status == 'in':
    print(title)
    Output: Wings of Fire, Gitanjali (before B1 is issued).

    items() gives (key, value) pairs; the value tuple is unpacked.

  3. (iii) · 1 mark

    A new book B4 'Malgudi Days' arrives. Add it, then remove B2 and show what pop returns.

    Answer

    Answer: books['B4'] = ('Malgudi Days', 'in'); books.pop('B2') returns ('Godan', 'out').

    Assignment to a new key adds; pop returns the value.

  4. (iv) · 1 mark

    A student types code 'b3'. Why does books['b3'] fail, and how can the program handle it?

    Answer

    Answer: Keys are case-sensitive, so 'b3' is not a key (KeyError). Use books.get(code.upper(), 'No such book').

    get() with a default avoids the error; upper() matches the stored keys.

Where the marks are

How a typical answer is split into step marks. Show every step: a right final answer alone rarely earns full marks.

Differentiate between a list and a tuple on any two points. [2 marks] (2 marks)

StepMarks
Mutability: a list is mutable; a tuple is immutable1
Syntax or use: list in [ ] with methods such as append and remove; tuple in ( ) with only count and index, and usable as a dictionary key1

Write a program to count the number of times each character appears in a string entered by the user, using a dictionary. [3 marks] (3 marks)

StepMarks
Input the string and create an empty dictionary0.5
Loop over characters: add 1 if the key exists, else set it to 1 (or use get)1.5
Print the dictionary or each key with its count1

Write a program to input the names and salaries of n employees into a dictionary, then (i) print all employees earning more than ₹50000, (ii) give every employee a 10% raise, and (iii) print the name of the highest-paid employee. [5 marks] (5 marks)

StepMarks
Input n; loop to read name and salary and store emp[name] = salary1
(i) Traverse with items() and print names with salary > 500001
(ii) Loop over keys: emp[k] = emp[k] * 1.11
(iii) Find max(emp.values()) and the key with that value1.5
Clear output0.5

Where students lose marks in Tuples and Dictionaries

The slips examiners see most often, and what to write instead.

  • Mistake: Writing a one-item tuple without a comma

    (5) is the int 5.

    Wrong working

    t = (5)
    print(type(t)) → tuple

    Right working

    t = (5,) → <class 'tuple'>

    Do this: Always add a trailing comma for one item.

    Usually costs: 1 mark

  • Mistake: Saying sorted(t) returns a tuple

    sorted always returns a list.

    Wrong working

    sorted((3, 1, 2)) = (1, 2, 3)

    Right working

    sorted((3, 1, 2)) = [1, 2, 3]; tuple(sorted(t)) gives a tuple

    Do this: Wrap with tuple() if a tuple is needed.

    Usually costs: 1 mark

  • Mistake: Using in to search dictionary values

    in checks keys only.

    Wrong working

    60 in {'mango': 60} → True

    Right working

    60 in d → False; 60 in d.values() → True

    Do this: Use d.values() for values.

    Usually costs: 1 mark

  • Mistake: Expecting update() to keep old values

    update overwrites the value of any key that already exists.

    Wrong working

    {'a': 1}.update({'a': 2}) leaves 'a' as 1

    Right working

    'a' becomes 2

    Do this: Check for common keys before updating.

    Usually costs: 1 mark

  • Mistake: Using a list as a dictionary key

    Keys must be immutable; lists are mutable.

    Wrong working

    d = {[1, 2]: 'pair'}

    Right working

    d = {(1, 2): 'pair'}

    Do this: Use a tuple instead of a list.

    Usually costs: 1 mark

NCERT exercise guide: Tuples and Dictionaries

What each exercise in the NCERT chapter tests, how to approach it, and a question of the same kind solved step by step. Questions here are written in our own words.

NCERT Chapter 10 exercise: outputs on tuples and dictionaries

What it tests: Results of tuple operations and functions, unpacking, and dictionary methods on given data.

How to approach it: For tuples, remember immutability and that sorted gives a list; for dictionaries, track the pairs in insertion order and the return value of each method.

Same kind as the 'give the output' questions

Give the output:

t = ('x', 'y') * 2 + ('z',)
print(t, t.index('y'), t.count('x'))
d = {1: 'one', 2: 'two'}
d[3] = d[1] + d[2]
print(d.get(4, 'none'), len(d), d[3])
Show the solutionSolution
  1. ('x', 'y', 'x', 'y', 'z'); first 'y' at 1; 'x' twice.
  2. d gets 3: 'onetwo'; key 4 absent → 'none'; 3 pairs.

Answer: ('x', 'y', 'x', 'y', 'z') 1 2
none 3 onetwo

NCERT Chapter 10 exercise: dictionary programs

What it tests: Building dictionaries from input, counting, searching by key, and changing values.

How to approach it: Use d[key] = value in a loop to build; get() to read safely; items() to traverse.

Same kind as the 'store month names and days' program

Create a dictionary of the first four months and their number of days (non-leap year) and print the months that have 31 days and the total number of days.

Show the solutionSolution
  1. m = {'Jan': 31, 'Feb': 28, 'Mar': 31, 'Apr': 30}
    for k, v in m.items():
        if v == 31:
            print(k, end=' ')
    print()
    print(sum(m.values()))

Answer: Jan Mar
120

Practice questions on Tuples and Dictionaries

Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.

  1. Q1 · 1 mark · MCQExam level

    Which of these creates a tuple? (a) t = (4) (b) t = [4] (c) t = 4, (d) t = {4}

    Hint

    Look for the comma.

    Answer

    (c) t = 4,

  2. Q2 · 2 marks · Short answerExam level

    Give the output: t = (5, 1, 8, 1); print(t.count(1), t.index(8), sorted(t), sum(t[1:]))

    Hint

    sorted gives a list.

    Answer

    2 2 [1, 1, 5, 8] 10

  3. Q3 · 1 mark · Very short answerHarder exam level

    d = {'a': 1, 'b': 2}. Give the output of print(d.pop('a'), d.pop('z', 0), d)

    Hint

    Default value avoids KeyError.

    Answer

    1 0 {'b': 2}

  4. Q4 · 1 mark · MCQHarder exam level

    Assertion (A): A dictionary can have a tuple as a key but not a list. Reason (R): Dictionary keys must be of an immutable type. Choose (a) both true, R explains A (b) both true, R does not explain A (c) A true, R false (d) A false, R true.

    Hint

    Why is a list rejected?

    Answer

    (a)

  5. Q5 · 2 marks · Short answerHarder exam level

    Predict the output:

    d = {}
    for ch in 'level':
        d[ch] = d.get(ch, 0) + 1
    print(d, len(d), max(d), min(d.values()))
    Hint

    max(d) compares keys.

    Answer

    {'l': 2, 'e': 2, 'v': 1} 3 v 1

  6. Q6 · 3 marks · Short answerExam level

    Write a program to input 5 numbers into a tuple and print the largest, smallest and mean, and how many times the largest occurs.

    Hint

    Build a list, then tuple().

    Answer

    L = []
    for i in range(5):
    L.append(int(input()))
    t = tuple(L)
    print(max(t), min(t), sum(t) / len(t), t.count(max(t)))

  7. Q7 · 3 marks · Short answerHOTS / competency

    Give the output:

    x = {'k': [1, 2]}
    y = x.copy()
    y['k'].append(3)
    y['j'] = 0
    print(x, y)
    Hint

    copy() is shallow: the list inside is shared.

    Answer

    {'k': [1, 2, 3]} {'k': [1, 2, 3], 'j': 0}

  8. Q8 · 2 marks · Short answerHarder exam level

    Write a program that takes a dictionary of states and capitals and prints it sorted by state name, with the capitals in uppercase.

    Hint

    sorted(d) gives keys in order.

    Answer

    cap = {'Kerala': 'Thiruvananthapuram', 'Bihar': 'Patna', 'Goa': 'Panaji'}
    for s in sorted(cap):
    print(s, cap[s].upper())
    Output: Bihar PATNA / Goa PANAJI / Kerala THIRUVANANTHAPURAM

  9. Q9 · 1 mark · Very short answerExam level

    Why does a, b = 10 fail while a, b = 10, 20 works? Name the error.

    Hint

    Unpacking needs a sequence.

    Answer

    10 is a single int and cannot be unpacked into two names: TypeError (cannot unpack non-iterable int). 10, 20 is a tuple of two items.

  10. Q10 · 3 marks · Short answerHOTS / competency

    Write a program to find which character occurs most often in 'mississippi' using a dictionary; if there is a tie, print all of them.

    Hint

    Find the highest count first, then all keys with it.

    Answer

    s = 'mississippi'
    f = {}
    for c in s:
    f[c] = f.get(c, 0) + 1
    hi = max(f.values())
    for c in f:
    if f[c] == hi:
    print(c, hi)
    Output: i 4 and s 4

  11. Q11 · 2 marks · Short answerHarder exam level

    What is the difference between d.clear() and del d?

    Hint

    Does the name still exist afterwards?

    Answer

    d.clear() empties the dictionary, which still exists as {}. del d deletes the name d itself; using d afterwards gives NameError.

  12. Q12 · 1 mark · Very short answerHarder exam level

    Give the output: print(dict.fromkeys((1, 2), 'x'), tuple({'a': 1, 'b': 2}))

    Hint

    tuple() of a dictionary takes its keys.

    Answer

    {1: 'x', 2: 'x'} ('a', 'b')

Test your recall

Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.

  1. 1.Is a tuple mutable?Show answer

    No.

  2. 2.What does (1, 2) * 2 give?Show answer

    (1, 2, 1, 2).

  3. 3.What error does a, b = (1, 2, 3) give?Show answer

    ValueError (too many values to unpack).

  4. 4.What does d.get('x') return when 'x' is not a key?Show answer

    None.

  5. 5.What does popitem() remove?Show answer

    The last inserted key-value pair, returned as a tuple.

  6. 6.What does dict.fromkeys('ab') give?Show answer

    {'a': None, 'b': None}.

  7. 7.What does len() of a dictionary count?Show answer

    The number of key-value pairs.

  8. 8.Can a tuple be a dictionary key?Show answer

    Yes, if its items are immutable.

Best order to study it

  1. Tuples: creation, one-item tuples, indexing, immutability.
  2. Tuple operations and the functions len, tuple, count, index, sorted, min, max, sum.
  3. Tuple assignment, swapping and nested tuples; tuple programs.
  4. Dictionaries: creation, keys and values, access with [ ] and get().
  5. Adding, modifying and deleting pairs; update, pop, popitem, clear.
  6. Traversal with keys(), values(), items(); max, min, sorted.
  7. fromkeys, copy, setdefault; character-count and employee programs.

Quick revision checklist

The night before the exam: can you do each of these without looking?

  • Tuple: immutable ordered sequence; (x,) for one item; t[0] = ... is a TypeError.
  • Tuple methods: count, index; sorted(t) returns a list.
  • Unpacking: a, b, c = t needs exactly 3 items; a, b = b, a swaps.
  • Dictionary: {key: value}; keys unique and immutable; values any type.
  • d[k] raises KeyError if missing; d.get(k) gives None or a default.
  • Add/modify: d[k] = v; delete: del, pop (value), popitem (last pair), clear.
  • update merges and overwrites; fromkeys makes keys with one value; setdefault adds only if missing.
  • keys(), values(), items(); in, max, min, sorted work on keys.

Tuples and Dictionaries: frequently asked questions

Are dictionary items in a fixed order?

Since Python 3.7, a dictionary keeps items in the order they were inserted, and printing or looping follows that order. Older textbooks call dictionaries unordered because you never access them by position.

What is the difference between del d[k] and d.pop(k)?

Both remove the pair. del is a statement and returns nothing; pop is a method that returns the removed value and can take a default so that a missing key does not raise KeyError.

Why use a tuple when a list can do everything a tuple can?

A tuple protects data that must not change, can be used as a dictionary key, and makes the intention clear. It is also slightly faster and smaller than a list.

Is the for...else structure used on this page in the syllabus?

No; it appears in one example only as a convenience. A found flag set inside the loop and checked after it, as in the lists chapter, gives the same result and is the safer exam answer.

How is max() used to find the key with the highest value?

max(d) gives the largest key, not the largest value. Find high = max(d.values()) and then loop through d to find the key whose value equals high.

Based on: CBSE Computer Science (083) syllabus, Class XI 2026-27; NCERT Computer Science, Textbook for Class XI, Chapter 10 Tuples and Dictionaries (Reprint 2026-27)