How to Create a Tuple from the List in Python?

In this tutorial, I have explained how to create a tuple from the list in Python. As a Python developer working on various projects for my clients across the USA I came across a scenario where I needed to create a tuple where data were stored in the list. After researching I found a few effective methods to achieve this task.

Create a Tuple from the List in Python

Let us learn how to create a tuple from the list in Python.

Read How to Find the Length of a Tuple in Python?

Method 1: Use the tuple() Constructor

Here, we start with a list of US states. The tuple() function takes this list and returns a new tuple containing the same elements

states = ["California", "New York", "Texas"] 
states_tuple = tuple(states)
print(states_tuple)  

Output:

('California', 'New York', 'Texas')

You can refer to the below screenshot to see the output.

Create a Tuple from the List in Python

The tuple() constructor in Python efficiently converts a list into a tuple, as demonstrated in the example. This method is easy and maintains the order of elements. It’s particularly useful when you need an immutable sequence derived from a list.

Check out How to Split a Tuple in Python?

Method 2: Use Tuple Packing

You can also create a tuple by simply separating elements with commas inside parentheses. This is known as tuple packing:

cities = ["Los Angeles", "Chicago", "Houston"]
cities_tuple = "Los Angeles", "Chicago", "Houston"  # tuple packing
print(cities_tuple)  

Output:

('Los Angeles', 'Chicago', 'Houston')

You can refer to the below screenshot to see the output.

How to Create a Tuple from the List in Python

Tuple packing in Python allows you to create a tuple by listing values separated by commas, optionally within parentheses. This method is concise and doesn’t require explicitly calling the tuple() constructor. It’s particularly useful for grouping related data into a single, immutable collection.

Read How to Reverse a Tuple in Python?

Convert a List of Lists to a List of Tuples in Python

Sometimes you may have a list of lists that you want to convert into a list of tuples. You can accomplish this using a list comprehension along with the tuple() function:

coordinates = [[40.7128, -74.0060], [34.0522, -118.2437], [29.7604, -95.3698]]
coordinates_tuples = [tuple(c) for c in coordinates]  
print(coordinates_tuples)   

Output:

[(40.7128, -74.006), (34.0522, -118.2437), (29.7604, -95.3698)]

You can refer to the below screenshot to see the output.

Create a Tuple from the List in Python example

To convert a list of lists into a list of tuples in Python, you can utilize a list comprehension combined with the tuple() function. This approach iterates over each sublist, converting it into a tuple, resulting in a new list where each element is a tuple. This method is efficient and maintains the original order of elements.

Check out How to Get the First Element of a Tuple in Python?

Conclusion

In this article, I have explained how to create a tuple from the list in Python. I discussed two methods to accomplish this task such as using the tuple() constructor , using tuple packing. I also covered how to convert a list of lists to a list of tuples.

You may read:

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.