Python list() Function: Syntax and 6 Examples

If you want a list from any iterable in Python, the Python list function is what you need. It takes a string, tuple, set, dict or generator and gives you back a list.

print(list("NYC"))
# ['N', 'Y', 'C']

In this tutorial, I’ll cover list() with six short examples you’ll actually use. Every output comes from Python 3.12.5 in Command Prompt.

Python list() Syntax

list(iterable=(), /)
ParameterRequiredDefaultDescription
iterableNo()Any iterable (positional only)

Return value: a new list with the same items in the same order. With no argument, you get [].

Note: the / means you can’t write iterable=. Other ways to build lists: how to create a list in Python.

When to Use list() in Python

  • Turning a tuple or set into something you can change
  • Grabbing dictionary keys, values or pairs
  • Making a quick shallow copy of a list
  • Seeing everything a range, map, zip or generator produces

Exporting rows to a CSV file for Excel? Creating an empty list in Python is the usual first step.

Example 1: Convert a String to a List of Characters

Let me start with a US city name:

city = "Austin"

print(list(city))
print(list())
print(list(""))

Output:

['A', 'u', 's', 't', 'i', 'n']
[]
[]
Python list function splitting a string into characters and creating empty lists in Command Prompt
Each character becomes an item.

How does this work? Python walked the string one character at a time. An empty call returned [].

To split by words instead, read converting a string to a list in Python.

Example 2: Convert a Tuple or Set to a List in Python

Tuples can’t change, and sets have no order:

prices = (19.99, 4.5, 120.0)
zip_codes = {78701, 10001, 60601}

price_list = list(prices)
price_list.append(7.25)
print(price_list)
print(sorted(list(zip_codes)))

Output:

[19.99, 4.5, 120.0, 7.25]
[10001, 60601, 78701]

How does this work? The tuple became a list, so append() worked. Sets have no order, so I added sorted().

More on sets: converting a set to a list.

Example 3: Get Dictionary Keys, Values and Items as a List

Here’s an inventory dictionary:

stock = {"SKU-101": 12, "SKU-205": 0, "SKU-310": 48}

print(list(stock))
print(list(stock.values()))
print(list(stock.items()))

Output:

['SKU-101', 'SKU-205', 'SKU-310']
[12, 0, 48]
[('SKU-101', 12), ('SKU-205', 0), ('SKU-310', 48)]
Python list function turning dictionary keys, values and items into lists in Command Prompt
Keys by default; .values() and .items() too.

How does this work? A dict loops over keys, so you got the SKUs. .items() gave (key, value) tuples.

See converting a dictionary to a list and the Python dict() function.

Example 4: Copy a List with list()

Passing a list makes a copy:

orders = ["Denver", "Boston", ["Miami", "Tampa"]]
backup = list(orders)

backup[0] = "Seattle"
backup[2].append("Orlando")
print(orders)
print(backup)
print(backup is orders)

Output:

['Denver', 'Boston', ['Miami', 'Tampa', 'Orlando']]
['Seattle', 'Boston', ['Miami', 'Tampa', 'Orlando']]
False
Python list function making a shallow copy where the nested list is still shared in Command Prompt
The nested list is shared.

How does this work? Changing backup[0] left orders alone, but the inner list is shared, so "Orlando" showed up in both.

Pro Tip: for nested data, use copy.deepcopy(); see shallow copy vs deep copy in Python.

Example 5: Convert range, map and zip Objects to a List

These return lazy objects:

states = ["tx", "ca", "ny"]
sales = [1250, 980, 1430]

print(list(range(2020, 2027, 2)))
print(list(map(str.upper, states)))
print(list(zip(states, sales)))

Output:

[2020, 2022, 2024, 2026]
['TX', 'CA', 'NY']
[('tx', 1250), ('ca', 980), ('ny', 1430)]

How does this work? list() pulled every value: map() uppercased states, zip() paired them with sales.

Learn more in the Python zip() function and enumerate() in Python.

Example 6: How Do I Convert a Generator to a List in Python?

Generators can only be read once:

readings = [71.2, 68.9, 74.5, 80.1]
hot = (r for r in readings if r > 70)

print(list(hot))
print(list(hot))

Output:

[71.2, 74.5, 80.1]
[]
Python list function reading a generator of temperature readings twice in Command Prompt
The second call is empty.

How does this work? The first call collected readings above 70. The generator was then used up, so the second returned [].

A list comprehension in Python does the same filter in one step.

Common Mistakes with Python list()

These are the Python list() errors I see most:

def m1(): return list(2026)
def m2(): return list("a", "b")
def m3(): return list(iterable="abc")
def m4():
    list = ["Reno"]
    return list("abc")

for n, test in enumerate([m1, m2, m3, m4], 1):
    try:
        test()
    except TypeError as err:
        print(f"{n}. TypeError: {err}")

Output:

1. TypeError: 'int' object is not iterable
2. TypeError: list expected at most 1 argument, got 2
3. TypeError: list() takes no keyword arguments
4. TypeError: 'list' object is not callable
Common Python list function errors: an int argument, two arguments, a keyword and a shadowed name
Four list() errors.
  1. Use [2026] for one number.
  2. Pass one iterable.
  3. Drop the keyword.
  4. Rename your list variable.

Fixes for the last one: list object is not callable in Python.

Wrapping Up the Python list() Function

Python’s list() function turns strings, tuples, sets, dicts and iterators into a fresh list. It also makes shallow copies.

Next, browse more Python built-in functions and methods.

For more list practice, try these:

What People Ask About Python list() Function

Is list() a function or a class in Python?

It’s a class. Calling list() creates a new list object.

Can list() convert a number to a list of digits?

Not directly. Use list(str(2026)), then int() on each item.

Does list() remove duplicates?

No. Use list(set(items)), but that loses the order.

Where can I read the full list() reference?

The signature and copy rules are in list() in the Python docs.