all Python 3Built-in functionsterm
list
types
Creates a mutable list from an iterable, or an empty list. list() with no arguments is equivalent to [].
Syntax
list(iterable)
list(other_list) makes a shallow copy: the outer list is new, but nested lists and objects are the same ones, so editing copy[0][0] shows up in the original. Applied to a generator, map or filter, list() drains it in one go, and a second call returns an empty list because the iterator is exhausted. Applied to a string it yields individual characters, not ['hello'] — for a one-element list write the brackets yourself.
Examples
print(list('hello')) # → ['h','e','l','l','o']
print(list(range(5))) # → [0,1,2,3,4]
print(list({1,2,3})) # → [1,2,3]
print(list({'a':1,'b':2})) # → ['a','b']
print(list(zip([1,2],[3,4]))) # → [(1,3),(2,4)]
See also
Open in the full glossarydocs.python.orgReport an inaccuracy