Dictionary in Python Class 11 Notes

Last updated on August 9th, 2026 at 07:36 pm

Dictionary in Python Class 11 Notes

 

Welcome to the complete Dictionary in Python โ€” Class 11 Notes. A dictionary is Python’s key-value data structure โ€” instead of finding items by position (like in a list), you find them by a unique key. It’s one of the most practical and most-asked chapters in CBSE Computer Science / Informatics Practices. These notes cover the complete CBSE syllabus โ€” accessing items, mutability, traversal, every built-in function/method, and the two suggested programs โ€” with syntax, examples and outputs.

๐Ÿ’ก Exam tip: The difference between dict[key] and dict.get(key), and between pop() and popitem(), are the two most repeated trick questions on this chapter. Both are explained below with examples.

Quick Overview โ€” What You Will Learn

#TopicKey ConceptsExam Weight
1Introduction to DictionaryKey-value pairs, creation, unique keysโญโญโญ
2Accessing ItemsUsing [ ] and get()โญโญโญ
3MutabilityAdding a new term, modifying an existing itemโญโญ
4Traversing a Dictionaryfor loop over keys, values, itemsโญโญ
5Built-in Functions/Methodslen(), dict(), keys(), values(), items(), get(), update(), del, clear(), fromkeys(), copy(), pop(), popitem(), setdefault(), max(), min(), sorted()โญโญโญ
6Suggested ProgramsCharacter frequency, employee salary dictionaryโญโญโญ

Section 1 ยท Introduction ยท โญโญโญ

๐Ÿ“ฆ What is a Dictionary in Python?

A dictionary is an unordered, mutable collection of key-value pairs, enclosed in curly braces { }. Instead of a numeric index, each value is accessed through its unique key.

Key-Value PairsMutableUnique Keysdict type

day = {1: “Monday”, 2: “Tuesday”, 3: “Wednesday”}
print(day)
print(type(day))
{1: ‘Monday’, 2: ‘Tuesday’, 3: ‘Wednesday’}
<class ‘dict’>

Key Rules for Dictionaries

Keys must be unique and of an immutable type (string, number, or tuple) โ€” a list or another dictionary can never be used as a key. Values, however, can be any type.

student = {“name”: “Amit”, “age”: 16, “marks”: [78, 85, 92]}
print(student)

# mylist = [1, 2]
# bad_dict = {mylist: “error”} # TypeError: unhashable type: ‘list’

{‘name’: ‘Amit’, ‘age’: 16, ‘marks’: [78, 85, 92]}
โš ๏ธ Board favourite: “Why can’t a list be used as a dictionary key?” โ€” because keys must be immutable (hashable), and lists are mutable.

Section 2 ยท Accessing Items ยท โญโญโญ

๐Ÿ”‘ Accessing Items in a Dictionary Using Keys

Dictionaries have no numeric index โ€” you access a value by writing its key inside square brackets, or by using the safer get() method.

day = {1: “Monday”, 2: “Tuesday”, 3: “Wednesday”}

print(day[1]) # Monday
print(day.get(1)) # Monday — safer way

print(day[9]) # KeyError: 9
print(day.get(9)) # None — no error!
print(day.get(9, “Not Found”)) # custom default value

Monday
Monday
KeyError: 9
None
Not Found
โš ๏ธ dict[key] vs get() โ€” most asked difference: dict[key] raises a KeyError if the key doesn’t exist. dict.get(key) returns None (or a default value you specify) instead of crashing the program โ€” much safer for real programs.

Section 3 ยท Mutability ยท โญโญ

โœ๏ธ Mutability of a Dictionary

A dictionary is mutable โ€” you can add new key-value pairs and modify existing ones after creation, using the same square-bracket syntax.

Adding a New Term

day = {1: “Monday”, 2: “Tuesday”, 3: “Wednesday”}
day[4] = “Thursday” # new key — added to dictionary
print(day)
{1: ‘Monday’, 2: ‘Tuesday’, 3: ‘Wednesday’, 4: ‘Thursday’}

Modifying an Existing Item

day = {1: “Monday”, 2: “Tuesday”, 3: “Wednesday”}
day[1] = “Sunday” # existing key — value gets updated
print(day)
{1: ‘Sunday’, 2: ‘Tuesday’, 3: ‘Wednesday’}
โœ… One rule, two behaviours: dict[key] = value โ€” if the key already exists, its value is updated; if the key is new, it is added. Python decides automatically.

Section 4 ยท Traversal ยท โญโญ

๐Ÿ”„ Traversing a Dictionary

You can loop through a dictionary’s keys, values, or key-value pairs together. By default, looping over a dictionary gives you its keys.

day = {1: “Monday”, 2: “Tuesday”, 3: “Wednesday”}

# Method 1 — loop gives keys by default
for key in day:
print(key, “-“, day[key])

# Method 2 — using items() for key AND value together
for key, value in day.items():
print(key, “->”, value)

1 – Monday
2 – Tuesday
3 – Wednesday
1 -> Monday
2 -> Tuesday
3 -> Wednesday
๐Ÿ’ก for key, value in dict.items() is the cleanest and most common way to traverse a dictionary โ€” memorise this pattern.

Section 5 ยท Built-in Functions/Methods ยท โญโญโญ

๐Ÿ› ๏ธ Built-in Functions and Methods on Dictionaries

The complete CBSE syllabus list: len(), dict(), keys(), values(), items(), get(), update(), del, clear(), fromkeys(), copy(), pop(), popitem(), setdefault(), max(), min(), sorted().

len() and dict()

day = {1: “Monday”, 2: “Tuesday”}
print(len(day)) # 2 — number of key-value pairs

pairs = dict([(1, “a”), (2, “b”)]) # list of tuples -> dict
print(pairs)

2
{1: ‘a’, 2: ‘b’}

keys(), values() and items()

day = {1: “Monday”, 2: “Tuesday”, 3: “Wednesday”}

print(day.keys())
print(day.values())
print(day.items())

dict_keys([1, 2, 3])
dict_values([‘Monday’, ‘Tuesday’, ‘Wednesday’])
dict_items([(1, ‘Monday’), (2, ‘Tuesday’), (3, ‘Wednesday’)])

update()

update() merges another dictionary into the current one โ€” existing keys get their values updated, and new keys get added.

day = {1: “Monday”, 2: “Tuesday”}
day.update({2: “TUESDAY”, 3: “Wednesday”})
print(day)
{1: ‘Monday’, 2: ‘TUESDAY’, 3: ‘Wednesday’}

del, clear(), pop() and popitem()

Four ways to delete: del removes one key; pop(key) removes one key AND returns its value; popitem() removes the last inserted pair; clear() empties the whole dictionary.

day = {1: “Monday”, 2: “Tuesday”, 3: “Wednesday”}

del day[1] # removes key 1
print(day)

removed_value = day.pop(2) # removes key 2, returns its value
print(removed_value)
print(day)

last_pair = day.popitem() # removes the last inserted pair
print(last_pair)
print(day)

day.clear() # empties the dictionary
print(day)

{2: ‘Tuesday’, 3: ‘Wednesday’}
Tuesday
{3: ‘Wednesday’}
(3, ‘Wednesday’)
{}
{}
โš ๏ธ pop() vs popitem() โ€” most asked difference: pop(key) removes a specific key you name and returns its value. popitem() takes no key โ€” it always removes the most recently added key-value pair as a tuple.

fromkeys()

Creates a new dictionary from a sequence of keys, all set to the same default value.

keys_list = [“a”, “b”, “c”]
new_dict = dict.fromkeys(keys_list, 0)
print(new_dict)
{‘a’: 0, ‘b’: 0, ‘c’: 0}

copy()

Returns a separate copy of the dictionary โ€” changes to the copy do not affect the original.

day = {1: “Monday”, 2: “Tuesday”}
day_copy = day.copy()
day_copy[3] = “Wednesday”
print(“Original:”, day)
print(“Copy:”, day_copy)
Original: {1: ‘Monday’, 2: ‘Tuesday’}
Copy: {1: ‘Monday’, 2: ‘Tuesday’, 3: ‘Wednesday’}

setdefault()

Similar to get(), but if the key is missing, it also inserts it into the dictionary with the given default value.

day = {1: “Monday”}
print(day.setdefault(2, “Tuesday”)) # key 2 missing -> inserted
print(day)
Tuesday
{1: ‘Monday’, 2: ‘Tuesday’}

max(), min() and sorted() on a Dictionary

When used directly on a dictionary, max(), min() and sorted() work on its keys by default.

marks = {“Amit”: 78, “Riya”: 92, “Sam”: 85}

print(max(marks)) # ‘Sam’ — largest key alphabetically
print(min(marks)) # ‘Amit’ — smallest key alphabetically
print(sorted(marks)) # sorted list of keys

# To work on VALUES instead of keys:
print(max(marks, key=marks.get)) # key with the highest value -> ‘Riya’

Sam
Amit
[‘Amit’, ‘Riya’, ‘Sam’]
Riya
โš ๏ธ Exam Alert: Plain max(dict) compares keys, not values. To find the key with the highest value (e.g. topper’s name), use max(dict, key=dict.get).

๐Ÿ“‹ Complete Summary Table โ€” All CBSE Syllabus Dictionary Methods

Function/MethodWhat it Does
len(dict)Number of key-value pairs
dict(seq)Creates a dictionary from key-value pairs
keys()Returns all keys
values()Returns all values
items()Returns all (key, value) pairs
get(key)Returns value for key, or None (no KeyError)
update(dict2)Merges dict2 into the dictionary
del dict[key]Removes one key-value pair
clear()Removes all key-value pairs
fromkeys(seq, val)New dict with given keys, same default value
copy()Returns a separate copy of the dictionary
pop(key)Removes given key, returns its value
popitem()Removes & returns the last inserted pair
setdefault(key, val)get(), but also inserts key if missing
max(dict) / min(dict)Largest / smallest key
sorted(dict)Sorted list of keys

Section 6 ยท Suggested Programs ยท โญโญโญ

๐Ÿ’ป Common Programs for CBSE Practicals & Board Exams

Program 1 โ€” Count Frequency of Characters in a String Using a Dictionary

text = “programming”
freq = {}

for ch in text:
if ch in freq:
freq[ch] += 1
else:
freq[ch] = 1

for key, value in freq.items():
print(key, “->”, value)

p -> 1
r -> 2
o -> 1
g -> 2
a -> 1
m -> 2
i -> 1
n -> 1
๐Ÿ’ก Shortcut using get(): the same loop can be written in one line: freq[ch] = freq.get(ch, 0) + 1 โ€” this avoids the if-else check entirely.

Program 2 โ€” Employee Names and Salary Dictionary

employees = {
“Amit”: 45000,
“Riya”: 52000,
“Sam”: 38000
}

# Accessing a specific employee’s salary
print(“Riya’s salary:”, employees[“Riya”])

# Traversing and displaying all employees with salary
for name, salary in employees.items():
print(name, “earns Rs.”, salary)

# Finding the highest-paid employee
topper = max(employees, key=employees.get)
print(“Highest paid:”, topper, “-“, employees[topper])

Riya’s salary: 52000
Amit earns Rs. 45000
Riya earns Rs. 52000
Sam earns Rs. 38000
Highest paid: Riya – 52000

Frequently Asked Questions

What is the difference between dict[key] and dict.get(key)?
dict[key] raises a KeyError if the key is missing. dict.get(key) returns None (or a chosen default) instead, avoiding a crash.

What is the difference between pop() and popitem()?
pop(key) removes a specific key you name and returns its value. popitem() takes no argument and always removes the last inserted key-value pair.

Can dictionary keys be a list?
No. Keys must be immutable (string, number, or tuple). A list is mutable, so it cannot be a key โ€” Python raises TypeError: unhashable type.

Is a dictionary ordered in Python?
From Python 3.7 onward, dictionaries maintain insertion order as an implementation detail, but conceptually for CBSE purposes a dictionary is treated as an unordered, key-based collection โ€” items are accessed by key, not by position.

What does setdefault() do differently from get()?
get() only reads a value. setdefault() reads the value too, but if the key doesn’t exist, it also inserts that key into the dictionary with the given default.

How do you find the key with the maximum value in a dictionary?
Use max(dict, key=dict.get) โ€” plain max(dict) only compares the keys, not the values.


Quick Practice Links

๐Ÿ“ Dictionary MCQs Class 11  |  Python Compiler  |  ๐Ÿ“‚ Practical File  |  ๐Ÿ“– All Class 11 Notes

Explore More Class 11 CS Notes

๐Ÿ“„ Python List  |  ๐Ÿ“Œ Python Tuple  |  ๐Ÿ“– Python String  |  ๐Ÿ”ง Python Functions

Found an error or a missing example? Drop a comment below โ€” we fix issues quickly. If these notes helped you, share this page with your classmates!

Jitendra Singh
โœ” Verified Educator

Jitendra Singh

Founder of CBSEPython.in

I help CBSE Class 9โ€“12 students learn Python, Information Technology, Artificial Intelligence and Computer Science through easy notes, quizzes, MCQs and sample papers.

Read More About Me โ†’