Write a Python Program to Convert a List to Tuple. In this language, we have a tuple function that converts the List items to Tuple. This example uses that function to convert the list to a tuple.
intList = [11, 22, 33, 44 ,55]
print("List Items = ", intList)
print("List Data Type = ", type(intList))
intTuple = tuple(intList)
print("\nTuple Items = ", intTuple)
print("Tuple Data Type = ", type(intTuple))

The program below uses the asterisk (*) operator to convert a list to a tuple. Don’t miss the comma at the end; otherwise, it throws a SyntaxError.
l = [10, 20, 30, 40]
t = (*l,)
print(t)
(10, 20, 30, 40)
Python Program to Convert List to Tuple
This Python example allows users to enter list items and use different options to convert the Python list to the Python Tuple.
list1 = []
number = int(input("Enter the Total List Items = "))
for i in range(1, number + 1):
value = int(input("Enter the %d List value = " %i))
list1.append(value)
print("List Items = ", list1)
print("List Data Type = ", type(list1))
intTuple = tuple(list1)
print("\nTuple Items = ", intTuple)
print("Tuple Data Type = ", type(intTuple))
intTuple1 = (*list1,)
print("\nTuple Items = ", intTuple1)
print("Tuple Data Type = ", type(intTuple1))
Enter the Total List Items = 4
Enter the 1 List value = 20
Enter the 2 List value = 50
Enter the 3 List value = 120
Enter the 4 List value = 90
List Items = [20, 50, 120, 90]
List Data Type = <class 'list'>
Tuple Items = (20, 50, 120, 90)
Tuple Data Type = <class 'tuple'>
Tuple Items = (20, 50, 120, 90)
Tuple Data Type = <class 'tuple'>
Program to convert a list to a tuple using list comprehension
In the program below, we use a list comprehension to iterate over list items. Next, we use the tuple() function to convert each list element to a tuple. This method allows us to perform math operations before converting to a tuple. Refer to a Python list comprehensions.
l = [10, 20, 30, 40]
t = tuple([i // 2 for i in l])
print(t)
(5, 10, 15, 20)
The following program uses a generator expression to convert a list to a tuple.
l = [10, 20, 30, 40]
t = tuple(i // 3 for i in l)
print(t)
(3, 6, 10, 13)
Program to convert a list to a tuple using lambda and map
Similar to the above, we can use map() and lambda() functions to perform some operations before converting the list to a tuple. Refer to Python map and Python lambda functions.
l = [10, 20, 30, 40]
t = tuple(map(lambda i: i * 2, l))
print(t)
(20, 40, 60, 80)
Also Read