There were no set literals in Python 2, historically curly braces were only used for dictionaries. Sets could be produced from lists (or any iterables):

set([1, 2, 3])
set([i for i in range(1, 3)])

To create an empty set, use

my_set = set()

Python 3 introduced set literals and comprehensions (see PEP-3100) which allowed us to avoid intermediate lists:

{1, 2, 3}
{i for i in range(1, 3)}

The empty set form, however, was reserved for dictionaries due to backwards compatibility. References from [Python-3000] sets in P3K? states:

I'm sure we can work something out --- I agree, {} for empty set and {:} for empty dict would be ideal, were it not for backward compatibility. I liked the "special empty object" idea when I first wrote the PEP (i.e., have {} be something that could turn into either a set or dict), but one of the instructors here convinced me that it would just lead to confusion in newcomers' minds (as well as being a pain to implement).

The following message describes these rules better:

I think Guido had the best solution. Use set() for empty sets, use {} for empty dicts, use {genexp} for set comprehensions/displays, use {1,2,3} for explicit set literals, and use {k1:v1, k2:v2} for dict literals. We can always add {/} later if demand exceeds distaste.

Answer from myaut on Stack Overflow
🌐
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 - They cannot be used as dictionary keys or stored inside other sets. Python provides frozenset, an immutable version of a set, which is hashable and can be used as a key or element in another set. When you need to eliminate duplicate elements from a list, converting the list to a set is a quick and efficient way to do so. ... Sets are ideal for performing mathematical operations like union, intersection, and difference, which are useful in fields like data analysis, database management, and computational biology.
🌐
Firmbee
firmbee.com › home › blog › python sets and dictionaries. part 4 python course from beginner to advanced in 11 blog posts
Python sets and dictionaries. Python course
February 7, 2022 - Python sets are collections of data that do not have any order or keys. A set does not store any data about its members other than their identity. Dictionaries are collections that map unique keys to values.
Discussions

dictionary - Difference between dict and set (python) - Stack Overflow
There were no set literals in Python 2, historically curly braces were only used for dictionaries. Sets could be produced from lists (or any iterables): ... Python 3 introduced set literals and comprehensions (see PEP-3100) which allowed us to avoid intermediate lists: More on stackoverflow.com
🌐 stackoverflow.com
When should I use a list, dictionary, tuple, or set in Python?
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? More on reddit.com
🌐 r/learnpython
24
100
March 6, 2025
What's the difference between a dictionary and a set?
The set is a dictionary without values. Before sets, it was common to use dicts with empty values to get the same properties. More on reddit.com
🌐 r/learnpython
13
5
June 27, 2020
Set, tuple and dictionary. What are the differences?
For starters, let's define mutable/immutable. Mutable objects can be changed by in-place assignment. Immutable objects do not. Sets, or lists, as I suspect you mean, are mutable. For example, if we have my_List=[0, 1, 4] and later state my_list[1]=2, then print(my_list), the ouput will be [0, 2, 4]. Tuples, like strings, do not support in-place assignment and immutable pairs. The syntax for tuples is similar to an ordered pair and is (x, y, ...). Tuples are oddly useful for returning packaged multiple outputs from a single function definition. Dictionaries work like functions, and are somewhat mutable. So, print(my_dict['key']) will output the value paired to 'key' as long as 'key' is in the dictionary. In Python, my_dict={ 'key1': val1, 'key2': val2, #etc } More on reddit.com
🌐 r/learnpython
8
0
February 15, 2020
🌐
Quora
quora.com › What-is-the-difference-between-set-and-dictionary-in-python
What is the difference between set and dictionary in python? - Quora
Answer (1 of 7): A set in python is a collection of items just like Lists and Tuples. Note the following about sets: * A set is created using the set keyword * A set cannot be an element of a set A dictionary in python is a collections of key-value pairs of item. For each entry, there are two ...
Top answer
1 of 3
97

There were no set literals in Python 2, historically curly braces were only used for dictionaries. Sets could be produced from lists (or any iterables):

set([1, 2, 3])
set([i for i in range(1, 3)])

To create an empty set, use

my_set = set()

Python 3 introduced set literals and comprehensions (see PEP-3100) which allowed us to avoid intermediate lists:

{1, 2, 3}
{i for i in range(1, 3)}

The empty set form, however, was reserved for dictionaries due to backwards compatibility. References from [Python-3000] sets in P3K? states:

I'm sure we can work something out --- I agree, {} for empty set and {:} for empty dict would be ideal, were it not for backward compatibility. I liked the "special empty object" idea when I first wrote the PEP (i.e., have {} be something that could turn into either a set or dict), but one of the instructors here convinced me that it would just lead to confusion in newcomers' minds (as well as being a pain to implement).

The following message describes these rules better:

I think Guido had the best solution. Use set() for empty sets, use {} for empty dicts, use {genexp} for set comprehensions/displays, use {1,2,3} for explicit set literals, and use {k1:v1, k2:v2} for dict literals. We can always add {/} later if demand exceeds distaste.

2 of 3
26

The syntax is not the same. Dictionaries used curly braces the first and you specify key-value pairs, where the key and value are separated by a colon:

>>> {'foo': 'bar'}
{'foo': 'bar'}
>>> type(_)
<type 'dict'>

Sets were added to the language later on, and the {..} curly brace notation only names elements, not pairs:

>>> {'foo'}
set(['foo'])
>>> type(_)
<type 'set'>

Note that in Python 2, the interpreter echoes the object using the set() callable. That's also how you specify an empty set:

>>> emptyset = set()

In Python 3, the newer {..} notation is used when echoing the object, unless it is empty:

>>> {'foo'}
{'foo'}
>>> _ - {'foo'}  # difference, removing the one element
set()

The set() type was added to the Python language in version 2.4 (see PEP 218), the curly brace syntax for set literals was added in Python 3 and back-ported to Python 2.7.

🌐
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 and dictionaries in Python both use curly brackets {}, which often confuses beginners. However, they serve different purposes. A set stores unique elements, while a dictionary stores key-value pairs where each key maps to a value. ... Dictionaries are designed to store relationships between ...
🌐
DZone
dzone.com › data engineering › data › python memo 2: dictionary vs. set
Python Memo 2: Dictionary vs. Set - DZone
April 15, 2021 - For a set, the difference is that there is no key-value pairing in the hash table, only a single element. Let's take a look at the hash table structure of the old version of Python:
Find elsewhere
🌐
Medium
medium.com › @pkrakesh › set-vs-dictionary-python-understanding-the-differences-861570724cc7
Set vs Dictionary Python: Understanding the Differences | by Rakesh PK | Medium
February 25, 2024 - Sets in Python are unordered collections of unique elements, while dictionaries are collections of key-value pairs. Sets do not allow duplicate elements, making them ideal for tasks that involve checking for membership or eliminating duplicates.
🌐
Just Academy
justacademy.co › blog-detail › difference-between-set-and-dictionary-in-python
Difference Between Set And Dictionary In Python by Roshan Chaturvedi | JustAcademy
While sets are enclosed in curly ... difference lies in the fact that sets are primarily concerned with the uniqueness of elements, whereas dictionaries focus on key-value relationships....
🌐
Enjoy Algorithms
enjoyalgorithms.com › blog › sets-and-dictionaries-in-python-for-ml
Sets and Dictionaries in Pyhton Programming
A dictionary is another data structure in Python that stores multiple data types in a ‘key and value’ pair. If we remember lists, we saw the integer indexes as addresses for the various elements present in the list.
🌐
Medium
medium.com › @bipinsatyankar1100 › set-vs-dictionary-in-python-a-beginner-friendly-guide-8a9bad75cc6d
Set vs Dictionary in Python: A Beginner-Friendly Guide | by Bipinsatyankar | Medium
June 25, 2026 - Each key in a dictionary is associated with a specific value, which makes dictionaries useful for storing related pieces of information together. Unlike sets, dictionaries do not store just values. Instead, they store a mapping between a key ...
🌐
CodeRivers
coderivers.org › blog › set-vs-dictionary-python
Python Sets vs Dictionaries: A Comprehensive Guide - CodeRivers
August 8, 2026 - They serve different purposes and understanding their differences can greatly enhance your Python programming skills. Sets are unordered collections of unique elements, while dictionaries are ordered collections of key-value pairs (insertion order is guaranteed since Python 3.7). Both use hash ...
🌐
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 - Use a set when uniqueness and membership matter more than order; for ordered unique passes, dict.fromkeys(...) or explicit list logic works. ... A dictionary maps hashable unique keys to values; lookups are by key, not by sequential index.
🌐
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 - Performing Set Operations: Use Set when you need to perform operations like union, intersection, or difference. Fixed, Non-Changing Data: Use Tuple when the data is fixed and should not be changed, such as configuration settings.
🌐
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
🌐
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 - 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.
🌐
InterServer
interserver.net › home › python › python lists, tuples, sets, and dictionaries: choosing a collection
Python Lists, Tuples, Sets, and Dictionaries: Choosing a Collection
August 4, 2025 - A list holds a changing sequence, a tuple holds a fixed sequence, a set tracks unique members, and a dictionary maps keys to values. None of these types alone provides access control or makes shared data safe from every kind of modification. Lists and tuples retain sequence order.
🌐
Simplilearn
simplilearn.com › home › resources › software development › your ultimate python tutorial for beginners › how to easily implement python sets and dictionaries
How to Easily Implement Python Sets and Dictionaries
January 26, 2025 - What are Python sets and dictionaries? Learn the various operations in a Python set, the various Python dictionary operations, methods, and more. Read on!
Address: 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
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.