What it is

Converting a set to a list means turning an unordered collection of unique, hashable elements into an ordered, indexable sequence. In practice, you’ll take a set and create a list containing the same elements.

Why it matters

Sets are ideal for fast membership tests and removing duplicates, but they don’t support indexing or slicing. Lists do. Converting lets you:

  • Index, slice, or reorder the elements
  • Sort the items or serialize them in a specific order
  • Pass data to APIs that require lists

How to use it

Method 1: Use the list() constructor (most direct)

The built-in list() constructor accepts any iterable—including sets and frozensets—and returns a new list.

# Set to list
s = {1, 2, 3, 4}
lst = list(s)
print(lst)     # e.g., [1, 2, 3, 4] (order is arbitrary)

Method 2: Unpack with [*iterable] (concise)

Starred unpacking turns any iterable into elements inside a new list literal. This general unpacking is specified in PEP 448.

s = {1, 2, 3, 4}
lst = [*s]
print(lst)     # e.g., [3, 1, 4, 2]

Method 3: Produce a sorted list

If you need a predictable order, use sorted() to return a list sorted by natural order. Elements must be mutually comparable.

s = {10, 2, 7, 3}
lst = sorted(s)
print(lst)     # [2, 3, 7, 10]

Method 4: Loop and append (explicit control)

More verbose, but useful if you want to transform elements during conversion.

s = {1, 2, 3, 4}
lst = []
for x in s:
    lst.append(x * 10)    # example transformation
print(lst)

Method 5: From a frozenset

Frozensets are immutable sets; conversion is identical with list(). See frozenset.

fs = frozenset({1, 2, 3})
lst = list(fs)
print(lst)

Limits and trade-offs

  • Order: Sets are unordered. The list you get from a set has arbitrary iteration order. Use sorted(s) if you need a deterministic order.
  • Comparability: sorted(s) requires all elements to be comparable; mixed types like {1, "a"} will raise a TypeError when sorted.
  • Performance: Converting is linear in the number of elements, O(n), for all straightforward methods (construction, unpacking, looping).
  • Hashability: Only hashable objects can live in a set. If you need to include unhashable items (like lists), you must convert them (e.g., to tuples) before they can be in a set.

FAQs

Does set → list preserve the original order?
No. Sets have no guaranteed order. If you need a specific order, use sorted(s) or apply your own key function with sorted(s, key=...).

I saw “TypeError: 'set' object is not callable.” What happened?
You probably overwrote the built-in name set with a variable, then tried calling it. Start a fresh shell or delete the variable, and avoid naming variables set or list.

set = {1, 2}     # bad: shadows the built-in
set([3, 4])      # TypeError

What’s the fastest way?
For plain conversion, list(s) and [*s] are both concise and O(n). Choose the one your team finds most readable.

How do I remove duplicates from a list and keep the first-seen order?
A common pattern is to deduplicate with an ordered dict of keys, then convert back to a list:

data = ["a", "b", "a", "c", "b"]
unique_preserving_order = list(dict.fromkeys(data))  # Python 3.7+
print(unique_preserving_order)  # ['a', 'b', 'c']

The class method is documented under dict.fromkeys.

Can I convert and sort at the same time?
Yes: sorted(s) returns a list, so you don’t need an extra constructor.

Quick reference

# Basic conversion
lst = list(s)

# Unpack into a list literal
lst = [*s]

# Sorted list
lst = sorted(s)

# Frozenset to list
lst = list(fs)

# Transform while converting
lst = [func(x) for x in s]