Sets are unordered, as you say. Even though one way to implement sets is using a tree, they can also be implemented using a hash table (meaning getting the keys in sorted order may not be that trivial).

If you'd like to sort them, you can simply perform:

sorted(set(y))

which will produce a sorted list containing the set's elements. (Not a set. Again, sets are unordered.)

Otherwise, the only thing guaranteed by set is that it makes the elements unique (nothing will be there more than once).

Hope this helps!

Answer from user on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_func_set.asp
Python set() Function
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... The set() function creates a set object.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-set-function
set() Function in python - GeeksforGeeks
2 weeks ago - set() function in Python is used to create a set, which is an unordered collection of unique elements.
Discussions

Why in Python do you have to create a set with the set() function instead of {}?
Because {} is the empty dictionary, not the empty set. Both sets and dictionaries use { and } as delimiters, and that's usually fine because you can look at the items: if they are key-value pairs ({name1: value1, name2: value2, ...}) then it's a dictionary, otherwise ({value1, value2, ...}) it's a set. But this doesn't work in the case where there are no items. So, Python makes the arbitrary decision that {} represents the empty dictionary, while for the empty set you need set(). More on reddit.com
๐ŸŒ r/learnpython
59
136
November 9, 2022
prettymaps: A small set of Python functions to draw pretty maps from OpenStreetMap data
this looks really nice, thanks for the post More on reddit.com
๐ŸŒ r/Python
69
1569
August 25, 2021
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ datastructures.html
5. Data Structures โ€” Python 3.14.3 documentation
Python also includes a data type for sets. A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference. Curly braces or the set() function can be used to create sets.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ functions.html
Built-in Functions โ€” Python 3.14.3 documentation
6 days ago - The function assigns the value to the attribute, provided the object allows it. For example, setattr(x, 'foobar', 123) is equivalent to x.foobar = 123. name need not be a Python identifier as defined in Names (identifiers and keywords) unless the object chooses to enforce that, for example in a custom __getattribute__() or via __slots__.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_ref_set.asp
Python Set Methods
Python Sets Access Set Items Add Set Items Remove Set Items Loop Sets Join Sets Frozenset Set Methods Set Exercises Code Challenge Python Dictionaries ยท Python Dictionaries Access Items Change Items Add Items Remove Items Loop Dictionaries Copy Dictionaries Nested Dictionaries Dictionary Methods Dictionary Exercises Code Challenge Python If...Else ยท Python If Python Elif Python Else Shorthand If Logical Operators Nested If Pass Statement Code Challenge Python Match ... Python Functions Python Arguments Python *args / **kwargs Python Scope Python Decorators Python Lambda Python Recursion Python Generators Code Challenge Python Range
Find elsewhere
๐ŸŒ
Python Reference
python-reference.readthedocs.io โ€บ en โ€บ latest โ€บ docs โ€บ sets
set โ€” Python Reference (The Right Way) 0.1 documentation
Common uses include membership testing, removing duplicates from a sequence, and computing standard math operations on sets such as intersection, union, difference, and symmetric difference.
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ set
Python Sets Explained: Efficient Lookups
To create a new set in Python, you can use curly braces ('{}') or the constructor function 'set()'.
๐ŸŒ
Hyperskill
hyperskill.org โ€บ university โ€บ python โ€บ set-and-set-in-python
Set and set() in Python
December 25, 2025 - To initialize a set in Python, you can use the set() function.
๐ŸŒ
docs.python.org
docs.python.org โ€บ 3 โ€บ library โ€บ sets.html
Built-in Types โ€” Python 3.7.3 documentation
The functools.cmp_to_key() utility is available to convert a 2.x style cmp function to a key function. reverse is a boolean value. If set to True, then the list elements are sorted as if each comparison were reversed.
๐ŸŒ
Real Python
realpython.com โ€บ python-sets
Sets in Python โ€“ Real Python
May 5, 2025 - In this example, you first create an empty set using the set() constructor. Then, you use the |= operator to add two people to the checked-in set. Next, you add more people using the .update() method. The built-in id() function lets you check that your set remains the same and that the updates are in-place operations.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ built-in โ€บ set
Python set()
Become a certified Python programmer. Try Programiz PRO! ... The set() function creates a set in Python.
๐ŸŒ
W3Schools
w3schools.com โ€บ PYTHON โ€บ python_sets.asp
Python Sets
Python Sets Access Set Items Add Set Items Remove Set Items Loop Sets Join Sets Frozenset Set Methods Set Exercises Code Challenge Python Dictionaries ยท Python Dictionaries Access Items Change Items Add Items Remove Items Loop Dictionaries Copy Dictionaries Nested Dictionaries Dictionary Methods Dictionary Exercises Code Challenge Python If...Else ยท Python If Python Elif Python Else Shorthand If Logical Operators Nested If Pass Statement Code Challenge Python Match ... Python Functions Python Arguments Python *args / **kwargs Python Scope Python Decorators Python Lambda Python Recursion Python Generators Code Challenge Python Range
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ set
Python Set (With Examples)
Creating an empty set is a bit tricky. Empty curly braces {} will make an empty dictionary in Python. To make a set without any elements, we use the set() function without any argument.
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ sets-in-python
Python Sets Tutorial: Set Operations & Sets vs Lists | DataCamp
December 13, 2022 - Learn about Python sets: what they are, how to create them, when to use them, built-in functions and their relationship to set theory operations.
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ c-api โ€บ set.html
Set Objects โ€” Python 3.14.3 documentation
The following functions are available for instances of set or its subtypes but not for instances of frozenset or its subtypes. ... Part of the Stable ABI. Return 1 if found and removed, 0 if not found (no action taken), and -1 if an error is encountered. Does not raise KeyError for missing keys. Raise a TypeError if the key is unhashable. Unlike the Python discard() method, this function does not automatically convert unhashable sets into temporary frozensets.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ set() in python
set() in Python | set() Function in Python - Scaler Topics
April 19, 2022 - The set() function is used to create a set in python. The set in python takes one parameter. It is an optional parameter that contains values to be inserted into the set.
๐ŸŒ
Cisco
ipcisco.com โ€บ home โ€บ python setย function
Python Set Function | How to Create Set With Set Function? โ‹† IpCisco
December 24, 2021 - Python set () function is used to create set object from any data type. For example, we use this method to convert tuples or lists to sets. In this Python lesson, we will focus on this function and learn how to convert other data types to python ...