Comprehensions: Set and Dict

comprehensions · multi

Description

Practice set and dict comprehensions. The syntax mirrors list comps
but with `{}` braces; for dicts you write `key: value` after the brace.

Aim to solve each in ONE expression. The dict-comprehension patterns
here cover the three things you'll do 90% of the time: build from a
sequence, invert an existing dict, and filter an existing dict.

Coverage map:
    set comp                          unique_lengths
    dict comp / build                 length_by_word
    dict comp / invert                invert_dict
    dict comp / filter                filter_dict_by_value

Constraints

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