RG's E-Learning Centre · Book a free demo class · WhatsApp +91-9379416374

Dictionary operations: Class 12 practice

Dictionaries map keys to values. The quick answer and an example come first; then the method, worked examples and six graded questions.

Dictionary operations: quick answer

Dictionaries map keys to values. d[k] = v adds or updates; d.get(k, default) avoids errors for missing keys; len(d) counts keys; iterating over d gives keys.

Example: d = {'a': 13, 'b': 19, 'c': 16} d['b'] = 31 print(d['b'], len(d)) Answer: 31 3.

  • Where it is taught: "Python Revision Tour", Class 12 Computer Science.
  • On this page: the method, 3 worked examples and 6 graded questions with a full answer key.

How to use this page (about 30 minutes)

  1. Read the method once, then cover the worked examples and try them yourself before reading the steps.
  2. Do the two Basic questions without notes. If either is wrong, re-read the matching worked example.
  3. Do the Standard and Challenge questions, then check every line of working against the answer key — not only the final answer.
  4. Write down the mistake behind each wrong answer and redo that question the next day.

What you should know first

  • Lists

The idea behind dictionary operations

Dictionaries map keys to values. d[k] = v adds or updates; d.get(k, default) avoids errors for missing keys; len(d) counts keys; iterating over d gives keys.

Step-by-step method

  1. Track the dictionary after each statement.
  2. Updating an existing key replaces the value.
  3. get() returns the default if the key is missing.

Worked example 1 (Basic)

d = {'a': 13, 'b': 19, 'c': 16} d['b'] = 31 print(d['b'], len(d))

  1. 'b' is updated to 31
  2. Still 3 keys
  3. Answer: 31 3

Worked example 2 (Standard)

d = {'a': 17, 'b': 1, 'c': 19} print(d.get('z', 40) + d['a'])

  1. 'z' missing → 40
  2. 40 + 17 = 57
  3. Answer: 57

Worked example 3 (Challenge)

d = {'a': 6, 'b': 5, 'c': 12, 'd': 19} s = 0 for k in d: s += d[k] print(s)

  1. Iterating gives keys; add each value
  2. = 42
  3. Answer: 42

Common mistakes and misconceptions

  • Thinking duplicate keys are kept
  • Expecting d[k] on a missing key to return None

Practice questions

  1. (Basic) d = {'a': 5, 'b': 14, 'c': 18} d['b'] = 24 print(d['b'], len(d))
  2. (Basic) d = {'a': 12, 'b': 16, 'c': 13} d['b'] = 28 print(d['b'], len(d))
  3. (Standard) d = {'a': 8, 'b': 9, 'c': 4} print(d.get('z', 32) + d['a'])
  4. (Standard) d = {'a': 4, 'b': 1, 'c': 12} print(d.get('z', 40) + d['a'])
  5. (Challenge) d = {'a': 19, 'b': 16, 'c': 2, 'd': 16} s = 0 for k in d: s += d[k] print(s)
  6. (Challenge) d = {'a': 19, 'b': 16, 'c': 8, 'd': 12} s = 0 for k in d: s += d[k] print(s)

Answer key with full working

  • Q1: 'b' is updated to 24 → Still 3 keys → Answer: 24 3
  • Q2: 'b' is updated to 28 → Still 3 keys → Answer: 28 3
  • Q3: 'z' missing → 32 → 32 + 8 = 40 → Answer: 40
  • Q4: 'z' missing → 40 → 40 + 4 = 44 → Answer: 44
  • Q5: Iterating gives keys; add each value → = 53 → Answer: 53
  • Q6: Iterating gives keys; add each value → = 55 → Answer: 55

Which textbook this practice follows

This skill is taught under "Python Revision Tour" in Class 12 Computer Science. Check your own textbook's contents page — CBSE, ICSE/ISC and state boards order chapters differently.

Answers on this page are generated and automatically re-checked by a second, independent calculation. They have not been reviewed by a teacher — if you spot a problem, tell us on WhatsApp.

Still stuck after the answer key?

If the same step in dictionary operations keeps going wrong, a short live 1 on 1 class can find the exact gap. The first demo class is free; send the class, board and chapter on WhatsApp (+91 9379416374).

Related practice and notes

More Class 12 Computer Science practice

Continue with this syllabus

Frequently asked questions

Which chapter is dictionary operations in?

This skill is taught under "Python Revision Tour" in Class 12 Computer Science. Check your own textbook's contents page — CBSE, ICSE/ISC and state boards order chapters differently.

Which question should I start with?

Start with the Basic questions. Move to Standard only when both Basic answers match the key with the same working; the Challenge questions combine this skill with earlier ones.

How were the answers checked?

Answers on this page are generated and automatically re-checked by a second, independent calculation. They have not been reviewed by a teacher — if you spot a problem, tell us on WhatsApp.

Is this only for CBSE?

The skill names follow NCERT/CBSE, but the method is the same for ICSE, state boards, IGCSE and IB. Only the chapter name and order differ.

Can I get live help with this topic?

Yes. RG's E-Learning teaches live 1 on 1 online classes; the first demo class is free and fees are shared after it.

Book a free demo class