This is a premium lesson. You can see the shape of every card — unlock to read them.
Unlock
DICTIONARY OPERATIONS AND MET……
Premium
This card is part of the premium lesson.
Unlock
Dictionary operations என்பது dictionary-ல் data-ஐ: create access add update delete search iterate cop……
Premium
This card is part of the premium lesson.
Unlock
Example
student = { "name": "Arun", "age": 20, "mark": 85 } M……
Premium
This card is part of the premium lesson.
Unlock
Dictionary: student = { "name": "Arun", "age": 20, "mark": 85 } இதைக் ஒரு student record என்று நினைத்துக்கொள்……
Premium
This card is part of the premium lesson.
Unlock
Basic dictionary
student = { "name": "Ravi", "age": 21, "mark": 90 } Structu……
Premium
This card is part of the premium lesson.
Unlock
Operation 1 create dictionary
Dictionary create செய்ய: stud……
Premium
This card is part of the premium lesson.
Unlock
or
Operation 2 access value
Value access செய்ய key பயன்படுத்த வேண்டும……
Premium
This card is part of the premium lesson.
Unlock
Here: student → dictionary "n……
Premium
This card is part of the premium lesson.
Unlock
Access using get
Another method: print(student……
Premium
This card is part of the premium lesson.
Unlock
Difference மிகவும் important. Using: stu……
Premium
This card is part of the premium lesson.
Unlock
Get with default
student = { "name": "Arun" } ……
Premium
This card is part of the premium lesson.
Unlock
Meaning
age key exists → actual value……
Premium
This card is part of the premium lesson.
Unlock
Operation 3 add item
New key-value pair add செய்ய: studen……
Premium
This card is part of the premium lesson.
Unlock
How add works
student["age"] = 20 Python check……
Premium
This card is part of the premium lesson.
Unlock
Operation 4 update value
Existing key-ன் value மாற்ற: student = { ……
Premium
This card is part of the premium lesson.
Unlock
Old
New
Comparison
Add vs update
Same syntax: dictionary[key] =……
Premium
This card is part of the premium lesson.
Unlock
Example
student["city"] = "Madurai" If city இல்லைய……
Premium
This card is part of the premium lesson.
Unlock
Operation 5 delete using del
student = { "name": "Arun", "age"……
Premium
This card is part of the premium lesson.
Unlock
del removes specified key-val……
Premium
This card is part of the premium lesson.
Unlock
Delete entire dictionary
del student இதனால் entire var……
Premium
This card is part of the premium lesson.
Unlock
Error
Premium
This card is part of the premium lesson.
Unlock
Operation 6 membership
Dictionary-ல் key இருக்கிறதா என்று check செ……
Premium
This card is part of the premium lesson.
Unlock
Example
Not in
print("city" not in student) ……
Premium
This card is part of the premium lesson.
Unlock
Important in operator
Dictionary-ல்: "name" in stud……
Premium
This card is part of the premium lesson.
Unlock
Example
Because "Arun" is a value. To……
Premium
This card is part of the premium lesson.
Unlock
Operation 7 length
student = { "name": "Arun", "……
Premium
This card is part of the premium lesson.
Unlock
Operation 8 iteration
Dictionary-ஐ for loop மூலம் iterate செய்யலாம். st……
Premium
This card is part of the premium lesson.
Unlock
By default dictionary iterati……
Premium
This card is part of the premium lesson.
Unlock
Loop keys
for key in student.keys(): pr……
Premium
This card is part of the premium lesson.
Unlock
Loop values
for value in student.values()……
Premium
This card is part of the premium lesson.
Unlock
Loop items
for key, value in student.ite……
Premium
This card is part of the premium lesson.
Unlock
Premium
This card is part of the premium lesson.
Unlock
How items works
student.items() produces pairs like: ("name", "Arun") ("age", 20) ("mark", 90) Then: for key, value……
Premium
This card is part of the premium lesson.
Unlock
Dictionary methods
Main dictionary methods: get() keys() values() items() update() po……
Premium
This card is part of the premium lesson.
Unlock
Example
Premium
This card is part of the premium lesson.
Unlock
Comparison
Get vs square bracket
Using: student["mark"] Missing key: KeyError Using:……
Premium
This card is part of the premium lesson.
Unlock
Method 2 keys
Returns all keys. student = { "name……
Premium
This card is part of the premium lesson.
Unlock
Keys loop
for key in student.keys(): pr……
Premium
This card is part of the premium lesson.
Unlock
Method 3 values
Returns all values. print(stu……
Premium
This card is part of the premium lesson.
Unlock
Values loop
for value in student.values()……
Premium
This card is part of the premium lesson.
Unlock
Method 4 items
Returns key-value pairs. prin……
Premium
This card is part of the premium lesson.
Unlock
Each pair is represented like……
Premium
This card is part of the premium lesson.
Unlock
Most important items use
for key, value in student.ite……
Premium
This card is part of the premium lesson.
Unlock
keys() → Key only values() → ……
Premium
This card is part of the premium lesson.
Unlock
Method 5 update
update() adds or modifies mul……
Premium
This card is part of the premium lesson.
Unlock
Example
student.update({ "age": 20, "……
Premium
This card is part of the premium lesson.
Unlock
Update existing
student = { "name": "Arun", "mark……
Premium
This card is part of the premium lesson.
Unlock
Existing key update ஆகிறது.…
Premium
This card is part of the premium lesson.
Unlock
Update multiple items
student.update({ "age": 20, "city": "Chenn……
Premium
This card is part of the premium lesson.
Unlock
Method 6 pop
pop() removes specified key and returns its value. student ……
Premium
This card is part of the premium lesson.
Unlock
Pop flow
student.pop("mark") does two ……
Premium
This card is part of the premium lesson.
Unlock
1. Finds "mark" 2. Removes it……
Premium
This card is part of the premium lesson.
Unlock
Result
Pop missing key
student.pop("city") If city key absent: Key……
Premium
This card is part of the premium lesson.
Unlock
Method 7 popitem
popitem() removes the last inserted key-value pair. studen……
Premium
This card is part of the premium lesson.
Unlock
popitem() returns: (key, valu……
Premium
This card is part of the premium lesson.
Unlock
Comparison
Pop vs popitem
Example
student.pop("age") removes age.……
Premium
This card is part of the premium lesson.
Unlock
Method 8 clear
Removes all items. student = { "na……
Premium
This card is part of the premium lesson.
Unlock
Dictionary variable still exi……
Premium
This card is part of the premium lesson.
Unlock
Comparison
Clear vs del
Premium
This card is part of the premium lesson.
Unlock
Result
Variable exists. But: del stu……
Premium
This card is part of the premium lesson.
Unlock
Method 9 copy
Creates a shallow copy. student = { "name":……
Premium
This card is part of the premium lesson.
Unlock
Comparison
Assignment vs copy
This is important. a = { "mark": 80 } b = a……
Premium
This card is part of the premium lesson.
Unlock
Why? a ──┐ ├── Same object b ……
Premium
This card is part of the premium lesson.
Unlock
Syntax
dictionary.setdefault(key, default_value) If key ex……
Premium
This card is part of the premium lesson.
Unlock
Example
Setdefault existing key
student = { "name": "Arun", "age……
Premium
This card is part of the premium lesson.
Unlock
Why? age already exists. It d……
Premium
This card is part of the premium lesson.
Unlock
Comparison
Setdefault vs update
Result
But: student.setdefault("age"……
Premium
This card is part of the premium lesson.
Unlock
Result
Because setdefault() keeps ex……
Premium
This card is part of the premium lesson.
Unlock
Method 11 fromkeys
Creates a new dictionary using a sequence ……
Premium
This card is part of the premium lesson.
Unlock
All keys receive same value.…
Premium
This card is part of the premium lesson.
Unlock
Fromkeys without value
keys = ["a", "b", "c"] data =……
Premium
This card is part of the premium lesson.
Unlock
Premium
This card is part of the premium lesson.
Unlock
Operation 9 merging dictionaries
Modern Python supports dictionary mergi……
Premium
This card is part of the premium lesson.
Unlock
Merging with duplicate key
a = { "x": 10 } b = { "x": 50……
Premium
This card is part of the premium lesson.
Unlock
Right-side dictionary value w……
Premium
This card is part of the premium lesson.
Unlock
Update merge
We can also merge using: a.up……
Premium
This card is part of the premium lesson.
Unlock
Example
Premium
This card is part of the premium lesson.
Unlock
Comparison
Difference
Comparison
Operation 10 comparison
Dictionaries can be compared using ==. ……
Premium
This card is part of the premium lesson.
Unlock
Dictionary equality mainly checks same key-va……
Premium
This card is part of the premium lesson.
Unlock
Dictionary comprehension
Dictionary can be created using comprehe……
Premium
This card is part of the premium lesson.
Unlock
Dry Run
Dry run comprehension
Nested dictionary operation
students = { "s1": { "name": "Arun", "mark": 90 }……
Premium
This card is part of the premium lesson.
Unlock
Update nested value
students["s1"]["mark"] = 95 N……
Premium
This card is part of the premium lesson.
Unlock
For loop nested dictionary
for sid, data in students.items(): pr……
Premium
This card is part of the premium lesson.
Unlock
Possible output
Table
Dictionary method summary
Table
Operations summary
Important difference 1
d["key"] versus: d.get("key") M……
Premium
This card is part of the premium lesson.
Unlock
Important difference 2
d.pop("key") versus: d.popitem() pop(key……
Premium
This card is part of the premium lesson.
Unlock
Important difference 3
d.clear() versus: del d clear() → items……
Premium
This card is part of the premium lesson.
Unlock
Important difference 4
b = a versus: b = a.copy() b = a → sa……
Premium
This card is part of the premium lesson.
Unlock
Important difference 5
keys() returns: keys values() r……
Premium
This card is part of the premium lesson.
Unlock
Common error 1
d = { "name": "Arun" } print(……
Premium
This card is part of the premium lesson.
Unlock
Error
KeyError Better: print(d.get(……
Premium
This card is part of the premium lesson.
Unlock
Common error 2
d = { "a": 1, "b": 2 } for x in d: print(x) Some stude……
Premium
This card is part of the premium lesson.
Unlock
Common error 3
d = {"a": 1} d.remove("a") Wrong. Dictionary ……
Premium
This card is part of the premium lesson.
Unlock
Common error 4
d = {"a": 1} d.append({"b": 2}) Wrong. Dict……
Premium
This card is part of the premium lesson.
Unlock
Common error 5
Trying positional access: d = { "name": "Arun"……
Premium
This card is part of the premium lesson.
Unlock
Remember dictionary method categories. Reading Methods get() keys() values() items(……
Premium
This card is part of the premium lesson.
Unlock
Remember this sequence: G K V I G → get() K → keys() V → values() I → ite……
Premium
This card is part of the premium lesson.
Unlock
Trb point 1
What is output? d = { "a": 10……
Premium
This card is part of the premium lesson.
Unlock
Trb point 2
d = { "a": 10, "b": 20 } prin……
Premium
This card is part of the premium lesson.
Unlock
Trb point 3
d = { "a": 10, "b": 20 } prin……
Premium
This card is part of the premium lesson.
Unlock
Trb point 4
d = { "a": 10, "b": 20 } print(d.items(……
Premium
This card is part of the premium lesson.
Unlock
Trb point 5
d = { "a": 10 } x = d.pop("a"……
Premium
This card is part of the premium lesson.
Unlock
Trb point 6
d = { "a": 1, "b": 2 } x = d.……
Premium
This card is part of the premium lesson.
Unlock
in modern Python insertion-or……
Premium
This card is part of the premium lesson.
Unlock
Trb point 7
What is returned by: d.clear()…
Premium
This card is part of the premium lesson.
Unlock
clear() modifies the dictiona……
Premium
This card is part of the premium lesson.
Unlock
Example
Trb point 8
What does this do? d.setdefault("x", 10) If "x"……
Premium
This card is part of the premium lesson.
Unlock
Interview point 1
Difference between get() and setdefault()? get(): d.get("age", 20) Missing key-க்கு 20 retu……
Premium
This card is part of the premium lesson.
Unlock
Example
Premium
This card is part of the premium lesson.
Unlock
Premium
This card is part of the premium lesson.
Unlock
Interview point 3
Do keys(), values(), and items() return lists? No. They retur……
Premium
This card is part of the premium lesson.
Unlock
Example
Which method gets a value wit……
Premium
This card is part of the premium lesson.
Unlock
Premium
This card is part of the premium lesson.
Unlock
Which returns all values?…
Premium
This card is part of the premium lesson.
Unlock
Which method returns key-valu……
Premium
This card is part of the premium lesson.
Unlock
Which method removes a specif……
Premium
This card is part of the premium lesson.
Unlock
Which method removes the last……
Premium
This card is part of the premium lesson.
Unlock
Which method removes all dict……
Premium
This card is part of the premium lesson.
Unlock
What does copy() create?…
Premium
This card is part of the premium lesson.
Unlock
What is output? d = {"a": 10}…
Premium
This card is part of the premium lesson.
Unlock
What happens? d = {"a": 10}…
Premium
This card is part of the premium lesson.
Unlock
Premium
This card is part of the premium lesson.
Unlock
Mcq 12
What does this return? dict.fromkeys(["a", "b"]) ……
Premium
This card is part of the premium lesson.
Unlock
Practice
Practice 1
Predict output: d = { "name": "R……
Premium
This card is part of the premium lesson.
Unlock
Practice
Practice 2
d = { "a": 1 } d["b"] = 2 pri……
Premium
This card is part of the premium lesson.
Unlock
Practice
Practice 3
d = { "a": 10, "b": 20 } d["a……
Premium
This card is part of the premium lesson.
Unlock
Practice
Practice 4
d = { "a": 1, "b": 2 } for ke……
Premium
This card is part of the premium lesson.
Unlock
Practice
Practice 5
d = { "a": 1, "b": 2 } x = d.……
Premium
This card is part of the premium lesson.
Unlock
Dictionary operations mainly include: Create Access Add Update Delete Search Loop Merge Compare Core syntax: ……
Premium
This card is part of the premium lesson.
Unlock
Short description
Dictionary Operations and Methods = Dictionary data-ஐ access, mod……
Premium
This card is part of the premium lesson.
Unlock