Convert List to Tuple in Python (original) (raw)

Last Updated : 08 Apr, 2025

The task of converting a list to a tuple in Python involves transforming a mutable data structure list into an immutable one tuple.

Using tuple()

The most straightforward and efficient method to convert a list into a tuple is by using the built-in tuple(). This method directly takes any iterable like a list and returns a tuple containing the same elements.

Python `

a = [1, 2, 3, 4, 5] # list

tup = tuple(a) print('tuple:', tup)

`

Output

tuple: (1, 2, 3, 4, 5)

Using * operator

Another method to convert a list to a tuple is by using the * operator to unpack the list and pass it as arguments to the tuple() . This is less commonly used but still an efficient and clean approach.

Python `

a = [1, 2, 3, 4, 5]

tup = (*a,) print('tuple:', tup)

`

Output

tuple: (1, 2, 3, 4, 5)

Using map()

We can also use the map() combined with the tuple() to convert a list into a tuple. While map() applies a given function to each item of the list, the result is then converted into a tuple.

Python `

a = [1, 2, 3, 4, 5]

tup = tuple(map(lambda x: x, a)) print('tuple:', tup)

`

Output

tuple: (1, 2, 3, 4, 5)

Using list comprehension

List comprehension generate the list elements and then passing the resulting list to the tuple() constructor. While functional, this approach is more verbose and involves an extra step to create the list before conversion to a tuple.

Python `

a = [1, 2, 3, 4, 5]

tup = tuple([x for x in a]) print('tuple:', tup)

`

Output

tuple: (1, 2, 3, 4, 5)

Similar Reads