Sponsored Reserved space — layout preview until AdSense is connected

Reference

list vs tuple vs set vs dict — pick the right one

A side-by-side reference for Python's core containers: when each is the right tool and what it costs.

May 2026 · 6 min read · 1 views · 0 hearts

list

Ordered, mutable, allows duplicates. The default for a sequence you will change. Membership tests are O(n).

tuple

Ordered, immutable. Great for fixed records and as dictionary keys. Slightly lighter than a list.

set

Unordered, unique elements, fast O(1) membership tests. Reach for it to deduplicate or check containment.

dict

Key/value mapping with O(1) lookups, insertion-ordered since Python 3.7. The workhorse for lookups by name.

Rule of thumb

  • Need order and changes? list.
  • Need a constant record? tuple.
  • Need uniqueness or fast membership? set.
  • Need lookup by key? dict.

Comments

Questions, corrections, and tips stay visible for everyone reading this page.

0 in thread

Join the discussion

Shown next to your comment.

Constructive tone · up to 4,000 characters

No comments yet

Be the first to leave a note — it helps the next reader.

Sponsored

Sponsored Reserved space — layout preview until AdSense is connected