A list keeps order, dict and set don't: when you care about order, therefore, you must use list (if your choice of containers is limited to these three, of course ;-) ).

dict associates each key with a value, while list and set just contain values: very different use cases, obviously.

set requires items to be hashable, list doesn't: if you have non-hashable items, therefore, you cannot use set and must instead use list.

set forbids duplicates, list does not: also a crucial distinction. (A "multiset", which maps duplicates into a different count for items present more than once, can be found in collections.Counter -- you could build one as a dict, if for some weird reason you couldn't import collections, or, in pre-2.7 Python as a collections.defaultdict(int), using the items as keys and the associated value as the count).

Checking for membership of a value in a set (or dict, for keys) is blazingly fast (taking about a constant, short time), while in a list it takes time proportional to the list's length in the average and worst cases. So, if you have hashable items, don't care either way about order or duplicates, and want speedy membership checking, set is better than list.

Answer from Alex Martelli on Stack Overflow
Top answer
1 of 13
646

A list keeps order, dict and set don't: when you care about order, therefore, you must use list (if your choice of containers is limited to these three, of course ;-) ).

dict associates each key with a value, while list and set just contain values: very different use cases, obviously.

set requires items to be hashable, list doesn't: if you have non-hashable items, therefore, you cannot use set and must instead use list.

set forbids duplicates, list does not: also a crucial distinction. (A "multiset", which maps duplicates into a different count for items present more than once, can be found in collections.Counter -- you could build one as a dict, if for some weird reason you couldn't import collections, or, in pre-2.7 Python as a collections.defaultdict(int), using the items as keys and the associated value as the count).

Checking for membership of a value in a set (or dict, for keys) is blazingly fast (taking about a constant, short time), while in a list it takes time proportional to the list's length in the average and worst cases. So, if you have hashable items, don't care either way about order or duplicates, and want speedy membership checking, set is better than list.

2 of 13
215
  • Do you just need an ordered sequence of items? Go for a list.
  • Do you just need to know whether or not you've already got a particular value, but without ordering (and you don't need to store duplicates)? Use a set.
  • Do you need to associate values with keys, so you can look them up efficiently (by key) later on? Use a dictionary.
🌐
Reddit
reddit.com › r/learnpython › when should i use a list, dictionary, tuple, or set in python?
r/learnpython on Reddit: When should I use a list, dictionary, tuple, or set in Python?
March 6, 2025 -

Hey everyone,

I’m trying to get a deeper understanding of Python’s built-in data structures—specifically lists, dictionaries, tuples, and sets. I understand their basic properties:

Lists (list) → Ordered, mutable, allows duplicates

Tuples (tuple) → Ordered, immutable, allows duplicates

Dictionaries (dict) → Key-value pairs, unordered (but ordered since Python 3.7), keys must be unique

Sets (set) → Unordered, mutable, unique elements only

But I'm struggling to figure out when to use each of them in real-world scenarios. I know some general guidelines, like:

Use lists when order matters and you need to modify elements.

Use tuples when you need an immutable sequence (e.g., function return values).

Use sets when you need fast lookups and uniqueness.

Use dictionaries when mapping keys to values efficiently.

However, I’d love to hear from experienced Python developers:

Are there any specific patterns or real-world examples where one of these structures is clearly the best choice?

Have you ever misused one and later realized another structure would have been better?

Are there any performance considerations that I should be aware of when choosing between them?

Looking forward to your insights! Thanks in advance.

Top answer
1 of 15
69
IMO: and this is controversial but will greatly help you organize your data, don't lump tuples in with lists, dictionaries, and sets. A tuple isn't a collection, it's a type. That is, use a tuple when your single object has multiple properties. Like a name or a coordinate. A first and last name together form a name, they don't have much value separately, and the constitute the entirely of the object. In this sense, a tuple of first_name, last_name is a single object, not a collection of separate strings. For example, a CSV file is "best" represented as a list of tuples. Each line is a single thing, but with multiple properties all of which are related. Column 1 and column 2 of a row aren't really a sequence or or collection, but rather feathers on the same chicken (tuple). However, Row 1 and row 2 are related only in that they are the same kind of thing stored together (list). We put the tuples in the list because the parts of the row are more related than the rows of the document. Think about type-hinting a tuple vs a list: a list hint takes exactly one type, and the expectation is that there will be several objects of that type. Conversely, a tuple hint easily accepts multiple types, but needs to know the exact number and position of each type. It's not so much that a tuple is an immutable container, but that a tuple stores an immutable thing. List: Use it when you need to store a lot of the same thing. It's ordered, but it doesn't need to be limited to ordered sequences. That is, a list is generally okay as long as the items don't need to be unordered. A list is good at iterating, but bad at selection, so use it when you will be looping over the items, but not selecting at random. Tuple: A tuple is one thing. You generally don't use it for storage, but for structure. When you have a thing with multiple parts, that's a tuple. When you have multiple things, that's a list. Unlike a list, a tuple is very likely to contain different types, while a list is (should) contain elements of a single type. Again, a tuple is good at iteration and bad at selection. A dictionary and set are really close to the same thing--they are hashes. Hashes are bad at iteration, but good at selection, so they are best when you need to select items from the container at random--not in order. They are semi-ordered, meaning you can now expect the order to remain, but if you need items to be in order it's probably not the right type. If you need a key->value relationship, then you want a dict, otherwise, you want a set. Use lists when order matters and you need to modify elements. Order doesn't need to matter, it just needs to be inconsequential. Also, avoid the "modify" criteria as almost all "real" collections are modifiable. Lists end up being sort of a "default", so without a reason to choose something else, or a reason to avoid a list, most of the time a list is fine. Use tuples when you need an immutable sequence (e.g., function return values). Again, look at this as a single object. Use tuples when you are returning a complex single object, not a sequence. You can return a list from a function just as easily as a tuple, so I don't consider return values a good selection criteria. However, your function should be returning "one thing", so in that sense a tuple makes sense, but from the other direction. Use sets when you need fast lookups and uniqueness. Use dictionaries when mapping keys to values efficiently. again, I would avoid thinking about sets and dictionaries as a top-level division. Instead, think "do I need a hash", and then "do I need key->value pairs" to choose between them. Is this not actually a collection of separate, but similar, objects? Then you want a tuple, or something more sophisticated like a NamedTuple, DataClass, or Class Is this a sequence? That is, do you need these items in order, or don't care about which one you get next, or will be dealing with all the items at once (even if one-by-one)? This is a list. Is this more of a "soup"? Where you want a specific item next, and don't care about order, or will be dealing with only specific objects at once?
2 of 15
27
Tuple example below: I work with a lot of spatial information (latitudes, longitudes, etc.) whenever I’m processing this information I always make sure it is stored as a tuple because I don’t want to ever accidentally mess with that information since it’s tied to a specific place that someone cares about. Being off by X amount could be a big deal.
People also ask

When should I use a set instead of a list in Python?
Use a set when you only care about unique membership and fast lookup, and order either does not matter or you sort explicitly; use a list when you need stable positions, duplicates, or stack-like operations at the end.
🌐
golinuxcloud.com
golinuxcloud.com › home › programming › python › python list vs tuple vs set vs dictionary
Python List vs Tuple vs Set vs Dictionary: Difference and When to Use
Is a Python dictionary ordered?
Since Python 3.7 (guaranteed in 3.8+), the built-in dict preserves insertion order when you iterate keys, values, or items; values are looked up by key, not by integer index like a list.
🌐
golinuxcloud.com
golinuxcloud.com › home › programming › python › python list vs tuple vs set vs dictionary
Python List vs Tuple vs Set vs Dictionary: Difference and When to Use
What is the main difference between a Python list and a tuple?
Both are ordered sequences and allow duplicates; lists are mutable (you can change elements, append, pop) while tuples are immutable (the tuple object itself cannot be resized or have elements reassigned without building a new tuple).
🌐
golinuxcloud.com
golinuxcloud.com › home › programming › python › python list vs tuple vs set vs dictionary
Python List vs Tuple vs Set vs Dictionary: Difference and When to Use
🌐
Scaler
scaler.com › home › topics › python › differences between list, tuple, set and dictionary in python
Difference between list, tuple, set dictionary in Python
April 2, 2024 - Sets store unique, unordered elements and do not allow duplicates. Dictionaries store ordered data as key-value pairs (from Python 3.7+), where keys must be unique—duplicate elements in dictionaries are not allowed for keys, but values can be duplicated. Want to understand how all 4 can work ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › differences-and-applications-of-list-tuple-set-and-dictionary-in-python
Differences and Applications of List, Tuple, Set and Dictionary in Python - GeeksforGeeks
October 3, 2025 - Explanation: We merge two sets using union (|) and find shared items using intersection (&). Dictionary in Python is an ordered (since Py 3.7) collection of data values, used to store data values like a map, which, unlike other Data Types that hold only a single value as an element.
🌐
Educative
educative.io › answers › list-vs-tuple-vs-set-vs-dictionary-in-python
List vs. tuple vs. set vs. dictionary in Python
Sets are represented in curly brackets. Dictionaries: A dictionary is an unordered collection of data that stores data in key-value pairs. Dictionaries are enclosed in curly brackets in the form of key-value pairs. Let’s first see the difference in terms of how we create them. ... The fundamental distinction that Python makes on data is whether or not the value of an object changes.
🌐
GoLinuxCloud
golinuxcloud.com › home › programming › python › python list vs tuple vs set vs dictionary
Python List vs Tuple vs Set vs Dictionary: Difference and When to Use
June 21, 2026 - Match the container to how you ... sequences (mutable vs immutable); sets give uniqueness without indexing; dicts map keys to values and keep insertion order in modern Python....
Find elsewhere
🌐
BYJUS
byjus.com › gate › difference-between-list-tuple-set-and-dictionary-in-python
Difference Between List, Tuple, Set, and Dictionary in Python
September 30, 2022 - The lists, on the other hand, are mutable. The sets are an unordered collection of data types. These are mutable, iterable, and do not consist of any duplicate elements. The set class in Python represents the set’s mathematical notion. In Python, the dictionary refers to a collection (unordered) of various data types.
🌐
Jerry Ng
jerrynsh.com › tuples-vs-lists-vs-sets-in-python
Tuples vs. Lists vs. Sets in Python - Jerry Ng
August 9, 2021 - In Python, there are four built-in data types that we can use to store collections of data. With different qualities and characteristics, these built-in data types are List (list), Tuple (tuple), Set (set), and Dictionary (dict).
🌐
InterServer
interserver.net › home › python › python lists, tuples, sets, and dictionaries: choosing a collection
Python Lists vs Tuples vs Sets vs Dictionaries
August 4, 2025 - Choose a Python collection according to how you need to access and change its data. A list holds a changing sequence, a tuple holds a fixed sequence, a set tracks unique members, and a dictionary maps keys to values.
🌐
Medium
zlliu.medium.com › python-lists-vs-dicts-vs-sets-vs-tuples-dc784d1e0daf
Python — Lists VS Dicts VS Sets VS Tuples | by Liu Zuo Lin | Medium
September 5, 2024 - I recently went back to school, and have to take a compulsory Python programming module. Which has been reinforcing my absolute basics once again (it’s been 7 years) And one topic that has been confusing my classmates who are new to programming is: when to use lists VS dicts VS sets VS tuples
🌐
Testbook
testbook.com › home › key differences › difference between list, tuple, set, and dictionary in python | testbook.com
Difference Between List, Tuple, Set, and Dictionary in Python | Testbook.com
The difference is that a tuple, unlike a list, is immutable. A Set in Python is an unordered collection of data types. These are mutable, iterable, and do not consist of any duplicate elements.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › difference between list, tuple, set, and dictionary in python
Understanding List, Tuple, Set, Dictionary in Python with Examples
September 1, 2025 - This guide has equipped you with ... in Python. Remember: use lists for ordered, mutable collections; tuples for fixed, immutable data; sets for unique items; and dictionaries for fast, key-value lookups....
🌐
Plain English
python.plainenglish.io › differences-between-list-tuple-set-and-dictionary-in-python-8ff01d1f370e
Differences Between List, Tuple, Set, and Dictionary in Python | by Parth Dangaroshiya | Python in Plain English
May 28, 2025 - List: Mutable (modifiable). Tuple: Immutable (non-modifiable). Set: Mutable, but elements inside must be immutable. ... Turning ideas into emotions. 📖 Novels. 🌏 Travel. 🧠 Human. 💼 Entrepreneurs. 🗳 Tech. Stories rooted in real lives, rebel minds, and restless roads. ... New Python content every day.
🌐
YouTube
youtube.com › kindson the tech pro
Difference Between List, Tuple, Set and Dictionary in Python - YouTube
This Tutorials explains the difference between List, Tuple, Set and Dictionary in Python# DIFFERENCE BETWEEN# LIST - square braces# TUPLE - rounded braces# S...
Published: December 26, 2018
Views: 154K
🌐
TutorialsPoint
tutorialspoint.com › article › differences-and-applications-of-list-tuple-set-and-dictionary-in-python
Differences and Applications of List, Tuple, Set and Dictionary in Python
March 27, 2026 - Use List when you need an ordered, ... records) Use Set when you need unique elements or set operations (e.g., removing duplicates, finding common elements) Use Dictionary when you need fast key-based lookups (e.g., user profiles, configuration settings, caching) Each Python data structure serves specific purposes: lists for ordered mutable sequences, tuples for immutable data, sets for unique elements, and dictionaries for key-value relationships...
🌐
Plain English
python.plainenglish.io › python-lists-vs-tuples-vs-sets-vs-dictionaries-d273573dca24
Python: Lists vs. Tuples vs. Sets vs. Dictionaries | Python in Plain English
September 16, 2023 - Lists and tuples can be indexed. Sets can’t be indexed. Dictionaries can be keyed because they have keys and values.
🌐
Pythondictionary
pythondictionary.org › home › data structure comparisons
Python Data Structures Comparison: Dict vs List vs Set vs Tuple | PythonDictionary.org | PythonDictionary.org
January 6, 2025 - # Dictionary: Track counts word_counts = {'apple': 3, 'banana': 2} # Set: Track unique items only unique_words = {'apple', 'banana', 'apple'} # {'apple', 'banana'} # Set operations set1 = {1, 2, 3} set2 = {2, 3, 4} print(set1 & set2) # Intersection: {2, 3} print(set1 | set2) # Union: {1, 2, 3, 4}
🌐
Jadubaba Tech
jadubabatech.wordpress.com › 2025 › 04 › 09 › list-tuple-set-and-dictionary-in-python
List, Tuple, Set, and Dictionary in Python – Jadubaba Tech
April 9, 2025 - Use lists when you need an ordered, changeable collection. Use tuples when you need a fixed collection of items. Use sets when you need unique elements and no duplicates. Use dictionaries when you want to associate values with unique keys.