Practice Questions for Dictionary and sets#
Initialize Empty Dictionary and Empty Set (Correct and Exam-Safe)#
# Empty dictionary
d = {}
# Empty set (important: {} creates a dictionary, not a set)
s = set()
print(type(d))
print(type(s))
Output
<class 'dict'>
<class 'set'>
A. Basic Level (10 Questions)#
Dictionary – Basic#
1. Create and access
Output
Alice
2. Add a new key-value pair
Output
{'id': 101, 'marks': 90}
3. Update a value
Output
{'apple': 120}
4. Get keys
Output
dict_keys(['a', 'b'])
5. Get values
Output
dict_values([10, 20])
Set – Basic#
6. Create a set
Output
{1, 2, 3}
7. Add element to set
Output
{1, 2, 3}
8. Remove element
Output
{1, 3}
9. Set length
Output
3
10. Membership test
Output
True
B. Intermediate Level (10 Questions)#
Dictionary – Intermediate#
1. Iterate through dictionary
Output
a 1
b 2
2. Use get()
Output
0
3. Count frequency
Output
{'a': 2, 'b': 2, 'c': 1}
4. Dictionary comprehension
Output
{1: 1, 2: 4, 3: 9}
5. Merge dictionaries
Output
{'a': 1, 'b': 2}
Set – Intermediate#
6. Union
Output
{1, 2, 3}
7. Intersection
Output
{2, 3}
8. Difference
Output
{1, 3}
9. Subset check
Output
True
10. Remove duplicates from list
Output
[1, 2, 3]
C. Expert Level (5 Questions)#
1. Invert a dictionary
Output
{1: ['a', 'c'], 2: ['b']}
2. Find common values across dictionaries
Output
{2}
3. Remove keys with duplicate values
Output
{'a': 1, 'b': 2}
4. Group words by length
Output
{2: ['hi', 'by'], 5: ['hello'], 6: ['python']}
5. Find symmetric difference of multiple sets
Output
{1, 4}
Daily-Life Based Advanced Questions (5)#
Each problem reflects a realistic scenario, uses dictionary and/or set, and includes input + output code.
Q1. Student Attendance Tracker (Deduplication + Count)#
Problem A teacher records roll numbers of students who entered the class multiple times. Remove duplicates and count total unique attendees.
Output
Unique students: {101, 102, 103, 104}
Total present: 4
Q2. Expense Categorization (Daily Spending)#
Problem You track daily expenses and want total spending per category.
Output
{'food': 200, 'travel': 80, 'shopping': 200}
Q4. Product Purchase Frequency (E-commerce)#
Problem An online store wants to know how many times each product was purchased.
Output
{'phone': 3, 'laptop': 2, 'tablet': 1}
Q5. Identify Unique Visitors Across Multiple Days (Website Analytics)#
Problem Each day’s website visitors are logged. Find total unique visitors.
Output
Unique visitors: {1, 2, 3, 4, 5, 6, 7, 8}
Total visitors: 8