Comprehensions: Basics

comprehensions · multi

Description

Practice the syntactic surface of list comprehensions: map, filter,
map+filter, conditional value, enumerate, zip, nested iteration,
and tuple-unpacking in the `for` clause.

Each function below has a one-line docstring prompt. Aim to solve each in
ONE expression (a list comprehension). If you find yourself reaching for
a loop body or a helper, you're probably fighting the comp — step back.

Coverage map:
    map / filter / map+filter         doubles, positives, squared_evens
    conditional value (ternary)       clamp_negatives
    enumerate                         indexed_positives
    zip                               pairwise_sums
    flatten / nested comp / product   flatten, transpose, cartesian
    unpacking in `for`                swap_pairs

Constraints

- Solve each prompt in a single expression where possible.
- Inputs may be empty; handle the empty case naturally (your comp
  should already do the right thing).
- Don't import anything; everything here is plain builtins.
solution.py
output
Run the cases to see results here.