🐍
Python
Python Data Structures & Coding Patterns — Data Engineer Edition
🐍
🐍
Python · Section 3 of 5

Python Data Structures & Coding Patterns — Data Engineer Edition

🔒

This section is locked

Unlock every deep-dive, lab, mock interview, and memory map across all 10 topics.

View Plans — from ₹299/month

Already have a plan? Sign in

Python Data Structures & Coding Patterns — Data Engineer Edition

💡 Interview Tip
Interviewers don't expect LeetCode hard. They want to see you handle dicts, sets, sorting, and basic algorithms cleanly. If you can do these patterns, you can handle any Python question they throw.

Memory Map

🧠 PYTHON PATTERNS → SHBCQ
PYTHON PATTERNSSHBCQ
──────────────────────────
SSets (intersection, union, difference)
HHash maps (Counter, defaultdict, grouping)
BBuilt-ins (sorted, zip, enumerate, any/all)
CCollections (deque, namedtuple, OrderedDict)
QQueue/Stack patterns (LIFO, FIFO, bracket matching)

Q01 — Set Operations for Data Comparison

Question: Given two sets of team members, find (a) common members, (b) members only in team A, (c) members in either but not both, and (d) all members combined.

Sample Input:

team_a = {"Alice", "Bob", "Charlie", "Diana"}
team_b = {"Bob", "Diana", "Eve", "Frank"}

Expected Output:

Common: ['Bob', 'Diana']
Only in A: ['Alice', 'Charlie']
Symmetric difference: ['Alice', 'Charlie', 'Eve', 'Frank']
All members: ['Alice', 'Bob', 'Charlie', 'Diana', 'Eve', 'Frank']

Solution 1 — Manual loop approach

python — editable
team_a = {"Alice", "Bob", "Charlie", "Diana"}
team_b = {"Bob", "Diana", "Eve", "Frank"}

# Find common members by checking each member of A in B
common = []
for member in team_a:
    if member in team_b:
        common.append(member)
print("Common:", sorted(common))
# Output: Common: ['Bob', 'Diana']

# Find members only in team A
only_a = []
for member in team_a:
    if member not in team_b:
        only_a.append(member)
print("Only in A:", sorted(only_a))
# Output: Only in A: ['Alice', 'Charlie']

# Find symmetric difference (in one but not both)
sym_diff = []
for member in team_a:
    if member not in team_b:
        sym_diff.append(member)
for member in team_b:
    if member not in team_a:
        sym_diff.append(member)
print("Symmetric difference:", sorted(sym_diff))
# Output: Symmetric differ