list()
The workhorse conversion. Its other job is forcing a lazy iterator to produce everything now, which is where the surprises live.
Common call
list(iterable)
Returns
a new list — always a fresh object, never the input
Replaces
[x for x in iterable] when no transformation is needed
Watch out
consumes generators; a second call gives an empty list
list([iterable])
→ list
Demo
Live evaluation
Try:
Inputs
iterablestra string to split into characters
Output
list('abc')
['a', 'b', 'c']
The demo feeds a string, because a string is the iterable whose expansion surprises people most: list("abc") gives ["a", "b", "c"], one element per character, not ["abc"]. Order is preserved and duplicates are kept — unlike set, list throws nothing away. An empty iterable gives an empty list rather than an error.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| iterable | iterable | no (()) | Any iterable — string, tuple, set, dict, generator, file. Omitted gives an empty list. |
Return value
list — A new list holding the items of iterable in order. With no argument, a new empty list.
Common patterns
Materialise a lazy iterator
map, filter, zip and generators produce nothing until consumed; list forces them.
results = list(map(str.upper, names))
Shallow-copy a list
A new outer list, but the same inner objects — the usual copy caveat applies.
backup = list(original)
Snapshot before mutating
Iterating a copy lets you safely modify the original inside the loop.
for item in list(items): if drop(item): items.remove(item)
Examples
1. From a string
list('abc')
Returns
['a', 'b', 'c']2. From a tuple
list(('a', 'b'))
Returns
['a', 'b']3. From a range
list(range(3))
Returns
[0, 1, 2]4. From a dict
list({'a': 1, 'b': 2})
Returns
['a', 'b'] # keys only5. Empty
list()
Returns
[]6. Nested stays one level
list([[1, 2], [3]])
Returns
[[1, 2], [3]]Pitfalls
1. A string explodes into characters
The single most common surprise. Wrapping a string in list to "make it a list of one" gives one element per character instead.
Per character
list('abc')
['a', 'b', 'c']
Wrap in brackets
['abc']
['abc']
2. A generator is consumed
list drains the iterator. Calling it twice on the same generator gives the items and then nothing, with no error to signal what happened.
Second call empty
g = (x for x in range(3)) list(g), list(g)
([0, 1, 2], [])
Keep the list
items = list(g) items, items
reusable
3. A dict gives keys, not pairs
Iterating a dict yields keys, so list(d) drops the values entirely. Reach for items() when you wanted both.
Values lost
list({'a': 1, 'b': 2})
['a', 'b']
Ask for pairs
list({'a': 1, 'b': 2}.items())
[('a', 1), ('b', 2)]
4. The copy is shallow
list(original) makes a new outer list whose elements are the SAME objects. Mutating a nested list shows through in both.
Shared inner
a = [[1], [2]] b = list(a) b[0].append(99) a
[[1, 99], [2]]
Deep copy
import copy b = copy.deepcopy(a)
fully independent
When to use
Use it
- Forcing a generator, map, filter or zip to produce its items
- Converting a tuple, set or dict view into something mutable
- Taking a snapshot before mutating a sequence you are iterating
- Making a shallow copy of a flat list
Reach for something else
- Transforming while converting → a list comprehension says more
- You only iterate once → skip it and iterate the iterable directly
- Nested data you will mutate → copy.deepcopy
Notes
Complexity
O(n) — every item is copied into the new list
Return
Always a new list; list(x) is never x, even when x is a list
CPython impl
Objects/listobject.c :: list___init___impl
Memory
Allocates an array sized for the input, with room to grow
Thread-safe
The construction is safe; the resulting list is not under concurrent mutation
FAQ
Because a string is an iterable of its characters, and list copies whatever the iterable yields. There is no special case for strings. If you want a single-element list, write ["abc"] instead.
list('abc') # ['a', 'b', 'c'] ['abc'] # ['abc']
History
1.0
list has been a core built-in type since the earliest Python.
2.2
list became a true type usable as a base class, rather than a factory function.