Comprehensions are one tool. Now you need three more: sorted() with a key argument for ranking, filter() with a lambda for predicate-based selection, and try/except for when a string doesn't parse as a number. Real data is messy — Week 2 is the repertoire for ranking it and surviving its surprises.
Why does try/except live in this week and not later? I'd have guessed it was a week-3 or week-4 topic.
Because the moment you start sorting and filtering real strings, you'll hit values that can't be parsed — "ten" instead of 10, an empty field, a stray letter in a number column. try/except is the tool that lets you keep the rest of the pipeline running. Sorting and errors are the same week because they show up in the same code.
So by Friday I'll rank a list of dicts, filter with a lambda, and parse numbers without crashes?
All three. Day 10 sorts dicts by a field. Day 11 ranks top-N descending. Day 12 filters with a lambda. Day 13 wraps int() in try/except. Day 14 composes multi-field sort with a tuple key. By Friday you can take a raw CSV and produce a cleaned, ranked report.
sorted(..., key=lambda)reverse=True and slicingfilter() + lambda for predicate-based selectiontry/except ValueError(primary, secondary)Goal: by Friday, ranking and safe parsing are both one-liners.
7 lessons this week
Comprehensions are one tool. Now you need three more: sorted() with a key argument for ranking, filter() with a lambda for predicate-based selection, and try/except for when a string doesn't parse as a number. Real data is messy — Week 2 is the repertoire for ranking it and surviving its surprises.
Why does try/except live in this week and not later? I'd have guessed it was a week-3 or week-4 topic.
Because the moment you start sorting and filtering real strings, you'll hit values that can't be parsed — "ten" instead of 10, an empty field, a stray letter in a number column. try/except is the tool that lets you keep the rest of the pipeline running. Sorting and errors are the same week because they show up in the same code.
So by Friday I'll rank a list of dicts, filter with a lambda, and parse numbers without crashes?
All three. Day 10 sorts dicts by a field. Day 11 ranks top-N descending. Day 12 filters with a lambda. Day 13 wraps int() in try/except. Day 14 composes multi-field sort with a tuple key. By Friday you can take a raw CSV and produce a cleaned, ranked report.
sorted(..., key=lambda)reverse=True and slicingfilter() + lambda for predicate-based selectiontry/except ValueError(primary, secondary)Goal: by Friday, ranking and safe parsing are both one-liners.