Dictionaries — Class 11 CBSE Computer Science revision notes
A 3-page visual revision sheet for Dictionaries, written for Class 11 CBSE Computer Science. Formulas, diagrams and the traps that cost marks, laid out to be read the night before rather than the term before. Free, and it opens inside CapCompass.
Page 1 as PDFA preview of page 1 — all 3 pages open full size in the app.
Dictionaries in one look
values found by name instead of by position, one key pointing to exactly one value
A dictionary maps keys to values
a dictionary holds key colon value pairs, separated by commas, and written inside curly braces
student = the name marks paired with 90, the name grade paired with A, is one such dictionary
a value is looked up by its key, never by a position, a dictionary keeps no index numbers at all
mutable: pairs can be added, changed, or removed after the dictionary is created
Reading and writing a value
student['marks'] returns the value stored under the key marks, and raises a KeyError if that key does not exist
student.get('marks') does the same lookup safely, returning None instead of raising an error when the key is missing
student.get('rank', 0) also takes a second argument, a default value handed back only when the key is missing
student['rank'] = 3 both adds a brand new pair when rank is not already a key, and overwrites the value when it is
One dictionary, key by key
key
value
name
Priya
marks
90
grade
A
Common dictionary methods
d.keys() returns a view of every key, d.values() a view of every value, d.items() a view of every key value pair together
d.update(other) merges another dictionary in, adding new keys and overwriting the values of any key already shared
d.pop(key) removes that key and returns its value, and raises a KeyError if the key is missing
del d[key] also removes a pair, but returns nothing at all
len(d) reports the number of pairs currently stored
Iterating a dictionary
Q. d = the key a paired with 1, the key b paired with 2, the key c paired with 3, trace: for k, v in d.items(): print(k, v)
d.items() gives one pair per turn, as a two-value tuple
first turn: k is a, v is 1, prints a 1
second turn: k is b, v is 2, prints b 2
third turn: k is c, v is 3, prints c 3
the order printed matches the order the pairs were inserted in, dictionaries remember insertion order
Answer: a 1, then b 2, then c 3, one line each
Page 1 of 3. The full sheet, all 3 pages, opens free in the app.
These notes are not a standalone PDF. CapCompass plans Computer Science chapter by chapter against your real exam dates and free hours, and when the plan reaches Dictionaries the sheet opens inside the study block itself — at the page covering the sub-topic that block is on, with the timer still running. Revision arrives at the moment the plan says revise, instead of having to be gone looking for.