</>CodexBash
All articles
Python and JavaScript

Lists vs tuples vs sets

Python's three everyday collections compared: ordered and mutable lists, fixed tuples that can be dictionary keys, and sets for fast membership and deduplication, with their performance, common operations, gotchas and a quick guide to choosing.

CodexBash, , 5 min read

Python gives you three built-in collections that look alike at first: [1, 2, 3], (1, 2, 3) and {1, 2, 3}. They behave very differently. A list is an ordered sequence you can change, a tuple is an ordered sequence you cannot change, and a set is an unordered group of unique values with very fast membership tests. Choosing the right one makes code clearer and, sometimes, thousands of times faster. This article compares them side by side.

Sign in to read the rest

The whole 5 minute article is free with an account, along with every problem, lesson and tutorial. No card.