Pythonic PatternsList & Dict Comprehensions
All courses

One-liners that spark joy (and code golf)

Comprehensions build lists, dicts, or sets from loops in a single expression.

evens = [n for n in nums if n % 2 == 0]
squares = {n: n*n for n in nums}

Quirk: Nested comprehensions read right-to-left. More than two levels and your reviewer will send a thoughtful PR comment.

Output
Press Run to execute your code.