Dictionary என்பது Python-ல் data-ஐ key : value pair format-…
Dictionary என்பது Python-ல் data-ஐ key : value pair format-ல் store செய்ய பயன்படும் built-in collection data type. Simple example: student = { "name": "Arun", "age": 20, "mark": 85 } இதில்: "name" → "Arun" "age" → 20 "mark" → 85 Left side:…
Premium — locked
Advanced
26 min
230 cards
34 programs 14 MCQs v3
This is a premium lesson. You can see the shape of every card — unlock to read them.
Unlock
Premium
This card is part of the premium lesson.
Unlock
Dictionary என்பது Python-ல் data-ஐ key : value pair format-ல் store செய்ய பயன்படும் built-in collection data ……
Premium
This card is part of the premium lesson.
Unlock
List-ல் values index number ம……
Premium
This card is part of the premium lesson.
Unlock
Example
student = ["Arun", 20, 85] இதில்: student[0] → Arun student[1] → 20 student[2] → 85 ஆனால் index 0, 1, 2 பார்த……
Premium
This card is part of the premium lesson.
Unlock
Real world idea
ஒரு student record: Name = Arun Age = 20 Mark = 85 City = Chennai Python dictionary: ……
Premium
This card is part of the premium lesson.
Unlock
Dictionary-ஐ இப்படிப் புரிந்துகொள்ளுங்கள்: Dictionary ↓ Key : ……
Premium
This card is part of the premium lesson.
Unlock
Example
Premium
This card is part of the premium lesson.
Unlock
Result
Basic syntax: dictionary_name……
Premium
This card is part of the premium lesson.
Unlock
Example
Dictionary uses: { } Curly braces. Each pair uses: : Co……
Premium
This card is part of the premium lesson.
Unlock
student = { student என்ற dictionary உருவாக்குகிறோம். "name": "Kumar"……
Premium
This card is part of the premium lesson.
Unlock
Key and value
Dictionary-ன் அடிப்படை concep……
Premium
This card is part of the premium lesson.
Unlock
Example
இதில்: brand → key Toyota → v……
Premium
This card is part of the premium lesson.
Unlock
Accessing dictionary values
Dictionary value access செய்ய key பயன்படுத்த வேண்ட……
Premium
This card is part of the premium lesson.
Unlock
Another
Important difference from list
List: data = ["Python", 25] Access: data[0] Dictionary: data = { "la……
Premium
This card is part of the premium lesson.
Unlock
Dictionary is mutable
Dictionary is mutable. Mutable means: ……
Premium
This card is part of the premium lesson.
Unlock
Example
Premium
This card is part of the premium lesson.
Unlock
Old value: 80 New value: 95…
Premium
This card is part of the premium lesson.
Unlock
Add new item
Existing dictionary-க்கு புதிய key-value pair add செய……
Premium
This card is part of the premium lesson.
Unlock
Important rule: If key does no……
Premium
This card is part of the premium lesson.
Unlock
Update existing item
If key already exists: studen……
Premium
This card is part of the premium lesson.
Unlock
Example
Premium
This card is part of the premium lesson.
Unlock
Comparison
Add vs update
Same syntax: dictionary[key] = value But beha……
Premium
This card is part of the premium lesson.
Unlock
Example
student["city"] = "Madurai" city இல்லை……
Premium
This card is part of the premium lesson.
Unlock
Duplicate keys
Dictionary keys must be uniqu……
Premium
This card is part of the premium lesson.
Unlock
Example
Why? Same key: "name" twice பயன்படுத்தப்பட்ட……
Premium
This card is part of the premium lesson.
Unlock
Dictionary: Duplicate keys → ……
Premium
This card is part of the premium lesson.
Unlock
Example
Both values same. No problem.……
Premium
This card is part of the premium lesson.
Unlock
Dictionary keys data types
Dictionary key commonly: String Integer Tuple போன்ற immutable typ……
Premium
This card is part of the premium lesson.
Unlock
String key
Most commonly string key use செய்வோம். empl……
Premium
This card is part of the premium lesson.
Unlock
Integer key
subjects = { 1: "Tamil", 2: "……
Premium
This card is part of the premium lesson.
Unlock
subjects[1] works. But: subje……
Premium
This card is part of the premium lesson.
Unlock
Values can have any type
Dictionary values can be almost any Python object. data = { "name": "Arun", "a……
Premium
This card is part of the premium lesson.
Unlock
Empty dictionary
Empty dictionary: data = {} C……
Premium
This card is part of the premium lesson.
Unlock
Dict function
Dictionary can also be created using dic……
Premium
This card is part of the premium lesson.
Unlock
Type check
student = { "name": "Arun" } ……
Premium
This card is part of the premium lesson.
Unlock
Len
len() gives number of key-value pairs. stud……
Premium
This card is part of the premium lesson.
Unlock
Why? Three pairs: name : Arun……
Premium
This card is part of the premium lesson.
Unlock
Get method
Normally: student["name"] value……
Premium
This card is part of the premium lesson.
Unlock
Example
Comparison
Square bracket vs get
This is very important. Suppose key not av……
Premium
This card is part of the premium lesson.
Unlock
Error
KeyError But: print(student.g……
Premium
This card is part of the premium lesson.
Unlock
So: dictionary[key] → missing key cau……
Premium
This card is part of the premium lesson.
Unlock
Get with default value
get() method-க்கு default value கொடுக்க……
Premium
This card is part of the premium lesson.
Unlock
Because "age" key இல்லை. Anot……
Premium
This card is part of the premium lesson.
Unlock
Keys method
All keys get செய்ய: student = { "name": "Arun", "age": 20……
Premium
This card is part of the premium lesson.
Unlock
Values method
All values: print(student.val……
Premium
This card is part of the premium lesson.
Unlock
Items method
Both keys and values get செய்……
Premium
This card is part of the premium lesson.
Unlock
Notice: Each pair returned as a……
Premium
This card is part of the premium lesson.
Unlock
keys() → keys only values() →……
Premium
This card is part of the premium lesson.
Unlock
For loop over dictionary
Dictionary loop மிகவும் important. student =……
Premium
This card is part of the premium lesson.
Unlock
By default dictionary loop re……
Premium
This card is part of the premium lesson.
Unlock
Why only keys
When writing: for x in student: Python treats it ……
Premium
This card is part of the premium lesson.
Unlock
Loop through keys
Explicitly: for key in studen……
Premium
This card is part of the premium lesson.
Unlock
Loop through values
for value in student.values()……
Premium
This card is part of the premium lesson.
Unlock
Loop through items
Key and value both: for key, ……
Premium
This card is part of the premium lesson.
Unlock
This is one of the most impor……
Premium
This card is part of the premium lesson.
Unlock
How items loop works
Suppose: student.items() produces pairs: ("name", "Arun") ("age", 20) ("mark", 90) Loop: for key, v……
Premium
This card is part of the premium lesson.
Unlock
Execution: First pair: ("A", ……
Premium
This card is part of the premium lesson.
Unlock
Print: A 10 Next: ("B", 20) U……
Premium
This card is part of the premium lesson.
Unlock
Print: B 20 Final output: A 1……
Premium
This card is part of the premium lesson.
Unlock
Check key exists
Use in. student = { "name": "……
Premium
This card is part of the premium lesson.
Unlock
Another
in checks keys, not values.…
Premium
This card is part of the premium lesson.
Unlock
Check value
To check value: print("Arun" ……
Premium
This card is part of the premium lesson.
Unlock
Not in
print("city" not in student)…
Premium
This card is part of the premium lesson.
Unlock
Premium
This card is part of the premium lesson.
Unlock
Remove item del
del removes an item using key. student = { "n……
Premium
This card is part of the premium lesson.
Unlock
Pop method
pop() removes specified key and returns its value. stu……
Premium
This card is part of the premium lesson.
Unlock
Popitem
popitem() removes the last inserted key-value pair. studen……
Premium
This card is part of the premium lesson.
Unlock
Returned value itself is a tu……
Premium
This card is part of the premium lesson.
Unlock
Clear
Remove all items: student.cle……
Premium
This card is part of the premium lesson.
Unlock
Dictionary still exists, but ……
Premium
This card is part of the premium lesson.
Unlock
Del dictionary
del student Entire variable is d……
Premium
This card is part of the premium lesson.
Unlock
Comparison
Clear vs del
clear() → removes all items → dictionary ……
Premium
This card is part of the premium lesson.
Unlock
Update method
Multiple values add/update செய்ய: student = { ……
Premium
This card is part of the premium lesson.
Unlock
Update existing key
student = { "name": "Arun", "mark……
Premium
This card is part of the premium lesson.
Unlock
Copy
Dictionary copy: student = { "name": "Arun……
Premium
This card is part of the premium lesson.
Unlock
a = student does not create an inde……
Premium
This card is part of the premium lesson.
Unlock
Example
Premium
This card is part of the premium lesson.
Unlock
Because: a ──┐ ├── same dicti……
Premium
This card is part of the premium lesson.
Unlock
Nested dictionary
Dictionary inside dictionary: students = { "student1": { "name": ……
Premium
This card is part of the premium lesson.
Unlock
Access nested dictionary
print(students["student1"]["n……
Premium
This card is part of the premium lesson.
Unlock
Think step-by-step: students["student1"] r……
Premium
This card is part of the premium lesson.
Unlock
Dictionary with list
Dictionary value can be a list. student = { "name……
Premium
This card is part of the premium lesson.
Unlock
First mark
Dictionary with tuple
student = { "name": "Arun", "subjects": ……
Premium
This card is part of the premium lesson.
Unlock
Fromkeys
dict.fromkeys() creates dictionary from keys with same ……
Premium
This card is part of the premium lesson.
Unlock
Setdefault
setdefault() checks a key. If key exists: 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. So e……
Premium
This card is part of the premium lesson.
Unlock
Dictionary order
Modern Python dictionaries preserve insertion order. data = { "a": 1, "b": 2, "c": 3 } Iteration normally fol……
Premium
This card is part of the premium lesson.
Unlock
Can we access by position
Suppose: student = { "name": "Arun", "age": 20 } This……
Premium
This card is part of the premium lesson.
Unlock
Example
Here 0 is a key, not a positi……
Premium
This card is part of the premium lesson.
Unlock
Hashable keys
Advanced important concept: Dictionary keys need to be hashable. Usually immutable objects can be keys. Valid……
Premium
This card is part of the premium lesson.
Unlock
Error
TypeError: unhashable type: '……
Premium
This card is part of the premium lesson.
Unlock
Tuple as key
Tuple can be a dictionary key……
Premium
This card is part of the premium lesson.
Unlock
Example
Dictionary comprehension
Similar to list comprehension……
Premium
This card is part of the premium lesson.
Unlock
Example
Meaning
Premium
This card is part of the premium lesson.
Unlock
Dry Run
Dry run dictionary comprehension
Comparison
List vs tuple vs set vs dictionary
Important methods
Main dictionary methods: keys() values() items() get() update() pop……
Premium
This card is part of the premium lesson.
Unlock
Common error 1
Wrong key: student = { "name"……
Premium
This card is part of the premium lesson.
Unlock
Error
KeyError: 'age' Better: print……
Premium
This card is part of the premium lesson.
Unlock
Common error 2
Wrong assumption: data = {"a": 10, "b": 20} print(data[0]) ……
Premium
This card is part of the premium lesson.
Unlock
Common error 3
Duplicate key: data = { "x": 10, "……
Premium
This card is part of the premium lesson.
Unlock
Common error 4
List as key: data = { [1, 2]:……
Premium
This card is part of the premium lesson.
Unlock
Error
TypeError: unhashable type: '……
Premium
This card is part of the premium lesson.
Unlock
Common error 5
Do not confuse: {} with empty set. Actual……
Premium
This card is part of the premium lesson.
Unlock
Empty set requires: set() Thi……
Premium
This card is part of the premium lesson.
Unlock
Dictionary remember செய்ய: Dictionary = Word me……
Premium
This card is part of the premium lesson.
Unlock
Example
"name" → "Arun" "age" → 20 So……
Premium
This card is part of the premium lesson.
Unlock
What is the output? d = { "a"……
Premium
This card is part of the premium lesson.
Unlock
Trb point 2
d = { "x": 1, "x": 2 } print(……
Premium
This card is part of the premium lesson.
Unlock
Reason: Dictionary keys must ……
Premium
This card is part of the premium lesson.
Unlock
Trb point 3
d = { "a": 10, "b": 20 } for ……
Premium
This card is part of the premium lesson.
Unlock
Default dictionary iteration ……
Premium
This card is part of the premium lesson.
Unlock
Trb point 4
What does items() return? d.items() Concep……
Premium
This card is part of the premium lesson.
Unlock
Trb point 5
What is: type({}) Answer: Not……
Premium
This card is part of the premium lesson.
Unlock
Trb point 6
What is: type(set()) Answer:…
Premium
This card is part of the premium lesson.
Unlock
Why dictionary access is fast? Python dictionaries use a hash table internally. When a key is provided: stude……
Premium
This card is part of the premium lesson.
Unlock
Interview point 2
Can dictionary keys be mutable? Generally, mutable types like list cannot be keys be……
Premium
This card is part of the premium lesson.
Unlock
Interview point 3
Difference between get() and []? d["key"] Missi……
Premium
This card is part of the premium lesson.
Unlock
Which symbol is used for dict……
Premium
This card is part of the premium lesson.
Unlock
Dictionary stores data as:…
Premium
This card is part of the premium lesson.
Unlock
What is the output? d = {"nam……
Premium
This card is part of the premium lesson.
Unlock
What happens? d = {"a": 1} pr……
Premium
This card is part of the premium lesson.
Unlock
What is the output? d = {"a":……
Premium
This card is part of the premium lesson.
Unlock
What is the output? d = {"a":……
Premium
This card is part of the premium lesson.
Unlock
Which method returns keys?…
Premium
This card is part of the premium lesson.
Unlock
Which method returns values?…
Premium
This card is part of the premium lesson.
Unlock
What does items() provide?…
Premium
This card is part of the premium lesson.
Unlock
What is the output? d = { "a"……
Premium
This card is part of the premium lesson.
Unlock
What is the type? x = {} prin……
Premium
This card is part of the premium lesson.
Unlock
Which creates an empty set?…
Premium
This card is part of the premium lesson.
Unlock
Dictionary keys are generally:…
Premium
This card is part of the premium lesson.
Unlock
Premium
This card is part of the premium lesson.
Unlock
Mcq 15
What is the output? d = {"x": 1……
Premium
This card is part of the premium lesson.
Unlock
Practice
Practice 1
Predict output: student = { "name":……
Premium
This card is part of the premium lesson.
Unlock
Practice
Practice 2
Predict: data = { 1: "A", 2: ……
Premium
This card is part of the premium lesson.
Unlock
Practice
Practice 3
Predict: d = { "a": 10, "b": ……
Premium
This card is part of the premium lesson.
Unlock
Practice
Practice 4
Predict: d = { "a": 10, "b": ……
Premium
This card is part of the premium lesson.
Unlock
Practice
Practice 5
Predict: d = { "a": 1, "b": 2……
Premium
This card is part of the premium lesson.
Unlock
Dictionary என்பது Python-ல் data-ஐ: key : value pairs-ஆக store செய்யும்……
Premium
This card is part of the premium lesson.
Unlock
Main methods: keys() values() items() get() update() pop() popitem() clear() copy() Most important rules: Dic……
Premium
This card is part of the premium lesson.
Unlock
Short description
Dictionary = Key-based mutable collection of key-value pairs. Easy memory: List → Index : Value Dictionary → ……
Premium
This card is part of the premium lesson.
Unlock