filter_complete_responses from yesterday gives you a clean list. Now your advisor wants a score per response — each one labelled with its row number so you can trace it back to the original export. How would you build that in Excel?
A helper column with row numbers and a formula referencing the satisfaction column. Two columns, manual formula drag.
In Python, enumerate() gives you both the index and the item at the same time. for i, r in enumerate(responses) means i is the position (0, 1, 2…) and r is the dict. You read r["satisfaction"] like a Qualtrics field name:
responses = [{"id": "r01", "satisfaction": 3.8}, {"id": "r02", "satisfaction": 4.2}]
for i, r in enumerate(responses):
print(f"Row {i}: {r['id']} → {r['satisfaction']}")
# Row 0: r01 → 3.8
# Row 1: r02 → 4.2Is enumerate a special keyword, or can I use it like a regular function?
It's a built-in function — no import needed. Call it on any list and it returns (index, item) pairs. for i, r in enumerate(...) unpacks each pair into two names in one line:
def score_per_response(responses: list) -> list:
scores = []
for i, r in enumerate(responses):
entry = {"id": format_response("Row", str(i)), "score": float(r["satisfaction"])}
scores.append(entry)
print(f"Extracted {len(scores)} scores")
return scoresEach entry is a dict with an ID and a float score — I can sort, filter, and average those directly in the next step.
Your helper column just became a list of dicts. No formulas, no dragging, no column alignment grief.
I used format_response from Day 3 inside the loop to label each entry. That's what it means to compose functions.
float(r["satisfaction"]) converts the string from the CSV to a number before storing it. Always convert types at the boundary — when you first read the value. Trying to average string "3.8" and string "4.2" later gives the wrong answer, no error.
for item in list: iterates items. for i, item in enumerate(list): iterates (index, item) pairs:
for i, r in enumerate(responses):
# i = 0, 1, 2... r = each dictCSV values are strings. Convert to float() or int() when you first read the value — not later when you try to compute with it.
range() alternativefor i in range(len(list)): works but is less Pythonic than enumerate(). Prefer enumerate() when you need both index and item.
filter_complete_responses from yesterday gives you a clean list. Now your advisor wants a score per response — each one labelled with its row number so you can trace it back to the original export. How would you build that in Excel?
A helper column with row numbers and a formula referencing the satisfaction column. Two columns, manual formula drag.
In Python, enumerate() gives you both the index and the item at the same time. for i, r in enumerate(responses) means i is the position (0, 1, 2…) and r is the dict. You read r["satisfaction"] like a Qualtrics field name:
responses = [{"id": "r01", "satisfaction": 3.8}, {"id": "r02", "satisfaction": 4.2}]
for i, r in enumerate(responses):
print(f"Row {i}: {r['id']} → {r['satisfaction']}")
# Row 0: r01 → 3.8
# Row 1: r02 → 4.2Is enumerate a special keyword, or can I use it like a regular function?
It's a built-in function — no import needed. Call it on any list and it returns (index, item) pairs. for i, r in enumerate(...) unpacks each pair into two names in one line:
def score_per_response(responses: list) -> list:
scores = []
for i, r in enumerate(responses):
entry = {"id": format_response("Row", str(i)), "score": float(r["satisfaction"])}
scores.append(entry)
print(f"Extracted {len(scores)} scores")
return scoresEach entry is a dict with an ID and a float score — I can sort, filter, and average those directly in the next step.
Your helper column just became a list of dicts. No formulas, no dragging, no column alignment grief.
I used format_response from Day 3 inside the loop to label each entry. That's what it means to compose functions.
float(r["satisfaction"]) converts the string from the CSV to a number before storing it. Always convert types at the boundary — when you first read the value. Trying to average string "3.8" and string "4.2" later gives the wrong answer, no error.
for item in list: iterates items. for i, item in enumerate(list): iterates (index, item) pairs:
for i, r in enumerate(responses):
# i = 0, 1, 2... r = each dictCSV values are strings. Convert to float() or int() when you first read the value — not later when you try to compute with it.
range() alternativefor i in range(len(list)): works but is less Pythonic than enumerate(). Prefer enumerate() when you need both index and item.
You have a filtered list of survey response dicts, each with an 'id' and 'satisfaction' field. She needs a labelled score list for her regression input. Write `score_per_response(responses)` that loops over the responses, extracts the satisfaction float from each, and returns a list of dicts like `[{'id': 'Row: 0', 'score': 3.8}, ...]`.
Tap each step for scaffolded hints.
No blank-editor panic.