#148EasyDictionaries & Sets· Set Operations

Common Elements

Two teams list the programming languages their members know. Write `compare_lists(a, b)` that returns a dictionary with three keys, in this order, each holding a sorted list without duplicates: - `"both"`: values that appear in both lists, - `"only_a"`: values that appear in `a` but not in `b`, - `"only_b"`: values that appear in `b` but not in `a`.

Input format

`a`, `b`: lists of strings.

Output format

A dictionary with keys `both`, `only_a` and `only_b`.

Examples

Input: a = ["python","sql","go","python"], b = ["rust","python","sql"]
Output: {"both":["python","sql"],"only_a":["go"],"only_b":["rust"]}
`python` and `sql` are shared; the repeated `python` is counted once.
Input: a = [], b = ["c"]
Output: {"both":[],"only_a":[],"only_b":["c"]}
Nothing is shared when one list is empty.

Constraints

  • 0 <= len(a), len(b) <= 10^4

Study first

  • #python
  • #sets
  • #set-operations