Week 2 down. You can now rank, filter, and survive bad data without crashes. How does it sit compared to comprehensions?
sorted with key=lambda clicked immediately after I understood it's just extracting the sort value. Try/except took a moment — I had to unlearn the instinct to check first.
Easier to ask forgiveness than permission is the Python way for unpredictable operations. Six questions to confirm the reflexes.
The multi-field sort with tuple keys — that one I want to test. I understood it conceptually but haven't used it enough.
It'll show up. Eighty percent to pass.
sorted(items, key=lambda x: x["field"]) — sort by a field without mutating the input. sorted returns a new list; .sort() mutates and returns None.
reverse=True — descending order. Combined with [:n] slicing, gives a top-N pattern.
filter(pred, xs) — keep items where the predicate returns truthy. Returns a lazy iterator; wrap in list().
try/except SpecificError — attempt a risky operation, catch the named exception, return a fallback. Never use bare except.
Tuple keys — key=lambda x: (primary, secondary) sorts by primary, with secondary as tiebreaker. Tuple comparison is lexicographic.
Week 2 down. You can now rank, filter, and survive bad data without crashes. How does it sit compared to comprehensions?
sorted with key=lambda clicked immediately after I understood it's just extracting the sort value. Try/except took a moment — I had to unlearn the instinct to check first.
Easier to ask forgiveness than permission is the Python way for unpredictable operations. Six questions to confirm the reflexes.
The multi-field sort with tuple keys — that one I want to test. I understood it conceptually but haven't used it enough.
It'll show up. Eighty percent to pass.
sorted(items, key=lambda x: x["field"]) — sort by a field without mutating the input. sorted returns a new list; .sort() mutates and returns None.
reverse=True — descending order. Combined with [:n] slicing, gives a top-N pattern.
filter(pred, xs) — keep items where the predicate returns truthy. Returns a lazy iterator; wrap in list().
try/except SpecificError — attempt a risky operation, catch the named exception, return a fallback. Never use bare except.
Tuple keys — key=lambda x: (primary, secondary) sorts by primary, with secondary as tiebreaker. Tuple comparison is lexicographic.