How to read & understand code written by someone else (and eventually be able to change it confidently)”
This is actually one of the top 3 most valuable real-world programming skills.
Let’s go very slowly and clearly — like I’m sitting next to you with a cup of chai. ☕
Step 1: Change your mindset first (most important part)
Most beginners think:
“I should understand every line immediately → if I don’t, I’m bad at coding.”
Reality (please remember this forever):
Good developers do NOT understand code instantly. They do exactly what I’m going to show you — slowly, line by line, like detectives.
So first promise to yourself:
“It’s completely okay if I don’t understand it on the first reading. My job is to investigate, not to be a genius in 10 seconds.”
Step 2: The golden 7-step method I use (and teach everyone)
Let’s take this very common real example that scares almost everyone when they first see it:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
def process_user_data(users): return [ { "id": u["user_id"], "full_name": f"{u['first']} {u['last']}".title(), "is_adult": u.get("age", 0) >= 18, "tags": [t.upper() for t in u.get("interests", []) if len(t) > 3] } for u in users if u.get("active", False) ] |
Terrifying at first? Yes. Understandable in 10–15 minutes? Also yes — if you follow the system.
Here’s exactly how I would explain it to you in person:
1. First — read the function name and parameters (10 seconds)
|
0 1 2 3 4 5 6 |
def process_user_data(users): |
Questions I ask myself out loud:
- What does this function probably do?
- What is users? (probably a list of dictionaries)
Answer: It takes a list of user dictionaries and “processes” them somehow → probably cleans them / transforms them / filters them.
2. Look at what the function returns (very important!)
|
0 1 2 3 4 5 6 |
return [ …… ] |
→ it returns a list → and inside the list there are dictionaries (because I see { … })
So most likely: it transforms the input list into a new, cleaner list of dictionaries.
3. Check if there’s a filter happening
Look for if outside the dictionary:
|
0 1 2 3 4 5 6 |
for u in users if u.get("active", False) |
→ only users where active is True will be included → inactive users are completely ignored
So now we know:
This function filters active users only and transforms them.
4. Now read one transformed user object — slowly, line by line
|
0 1 2 3 4 5 6 7 8 9 10 11 |
{ "id": u["user_id"], "full_name": f"{u['first']} {u['last']}".title(), "is_adult": u.get("age", 0) >= 18, "tags": [t.upper() for t in u.get("interests", []) if len(t) > 3] } |
Let’s break each key-value pair:
-
“id”: u[“user_id”] → just renaming “user_id” → “id” (common cleanup)
-
“full_name”: f”{u[‘first’]} {u[‘last’]}”.title() → take first name + space + last name → make it Title Case (first letter of each word capital) Example: “john” + ” ” + “doe” → “john doe” → “John Doe”
-
“is_adult”: u.get(“age”, 0) >= 18 → get age, if no age exists → use 0 → check if age ≥ 18 → gives True or False
-
“tags”: [t.upper() for t in u.get(“interests”, []) if len(t) > 3] This line scares people most — let’s destroy the fear:
It is just a list comprehension with a filter.
Let’s write it the long ugly way first:
|
0 1 2 3 4 5 6 7 8 9 |
tags = [] for t in u.get("interests", []): # if no interests → empty list if len(t) > 3: tags.append(t.upper()) |
So:
- take each interest
- if it has more than 3 letters
- make it UPPERCASE
- keep it in the new list
Examples:
|
0 1 2 3 4 5 6 7 8 |
interests = ["music", "art", "food", "tv", "dance"] → new tags = ["MUSIC", "DANCE"] # "art","food","tv" are ≤ 3 letters |
5. Put everything together in plain English
This function:
- Takes a list of user dictionaries
- Keeps only active users
- For each active user creates a new simpler dictionary with:
- id (renamed from user_id)
- full_name (First Last in title case)
- is_adult (True/False)
- tags (uppercase interests that are longer than 3 letters)
6. Test it mentally with example data
Input:
|
0 1 2 3 4 5 6 7 8 9 10 |
users = [ {"user_id": 1, "first": "alice", "last": "smith", "age": 17, "active": True, "interests": ["reading", "gaming", "art"]}, {"user_id": 2, "first": "bob", "last": "jones", "age": 25, "active": False, "interests": ["football", "music"]}, {"user_id": 3, "first": "clara", "last": "brown", "age": 32, "active": True, "interests": ["yoga", "travel", "tv"]} ] |
What should come out?
Only alice and clara are active.
Output:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[ { "id": 1, "full_name": "Alice Smith", "is_adult": False, # 17 < 18 "tags": ["READING", "GAMING"] # "art" too short }, { "id": 3, "full_name": "Clara Brown", "is_adult": True, "tags": ["TRAVEL"] # "yoga" = 4, "tv" = 2 } ] |
Perfect.
7. Last step: Say it out loud in one sentence
“This function cleans a list of users, keeps only active people, renames some keys, creates a proper full name, checks if they’re adult, and keeps only longer interests in uppercase.”
Now you understand 100% of it.
Summary: Your personal “I’m stuck” checklist
Whenever you see scary code:
- Read function name + parameters
- Look at what it returns
- Check if there’s filtering (if outside)
- Read one created item slowly — key by key
- Translate short lines into long obvious code
- Test mentally with 2–3 example items
- Say the whole purpose in one normal English sentence
Do this 30–40 times and you’ll become scary-good at reading other people’s code.
Would you like me to do exactly the same detailed breakdown for:
- nested loops
- recursion
- list/dict/set comprehensions
- classes & objects (OOP)
- async/await
- error handling (try/except)
- decorators
- regular expressions
- OR any other topic you’re struggling with right now?
Just tell me what you want to truly understand — I’ll go just as slowly and clearly. 😄
