The list function

The list function creates a new list from the original object. In the parameter, we specify the object from which we will make the list.

Syntax

pythonlist(the object from which we make a list)

Example

Let's use the list function to make a list from a string:

pythontxt = 'abcdef'
lst = list(txt)
print(lst)

Result of code execution:

python['a', 'b', 'c', 'd', 'e', 'f']

Example

Now let's make a list from a tuple:

pythontlp = ('ab', 1, 'cd', 2)
lst = list(tlp)
print(lst)

Result of code execution:

python['ab', 1, 'cd', 2]

Example

Let's make a list of the many:

pythonst = {1, 2, 3, 4}
lst = list(st)
print(lst)

Result of code execution:

python[1, 2, 3, 4]

See also

  • function dict,
    which creates a dictionary
  • function str,
    which creates a string
  • function tuple,
    which creates a tuple