Repaso
EspaƱol
PythonCorePY-54

What is len({1, 2, 2, 3, 3, 3})?

Options

  1. 6
  2. 3 (Correct option)
  3. 1
  4. TypeError

Answer

3

Why

A set keeps only unique values, so duplicates are dropped: {1, 2, 3}, which has length 3.

Sets are also very fast to check membership (x in s).

Common trick: list(set(items)) removes duplicates (but does not keep the order).

Remember

Set = unique values, fast lookups.

Key terms

Practice this question in Repaso