Python 3 reference · Built-in Functions

Python list() Function

Create a list: an ordered, changeable sequence. Called with an iterable, it copies its items into a new list.

Python 3 Since 3.0

Syntax

list(iterable=())

Parameters

ParameterDescription
iterable optional Items for the new list.

Return value

A new list.

Examples

Build a list from an iterableTry it yourself
print(list("abc"))
print(list(range(5)))
print(list({"x": 1, "y": 2}))  # a dict gives its keys

Output

['a', 'b', 'c']
[0, 1, 2, 3, 4]
['x', 'y']
Copy a listTry it yourself
original = [1, 2, 3]
copy = list(original)
copy.append(4)
print(original, copy)

Output

[1, 2, 3] [1, 2, 3, 4]
Turn an iterator into a listTry it yourself
squares = map(lambda n: n * n, [1, 2, 3])
print(squares)        # a lazy map object
print(list(squares))  # materialise it

Output

<map object at 0x1a353e0>
[1, 4, 9]

Version history

VersionChange
Python 3.0Added