

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert a list into a tuple in Python.
Sometimes during data analysis using Python, we may need to convert a given list into a tuple. Because some downstream code may be expecting to handle tuple and the current list has the values for that tuple. In this article we will see various ways to do that.
With tuple
This is a straight way of applying the tuple function directly on the list. The list elements get converted to a tuple.
Example
listA = ["Mon",2,"Tue",3] # Given list print("Given list A: ", listA) # Use zip res = tuple(listA) # Result print("The tuple is : ",res)
Output
Running the above code gives us the following result −
Given list A: ['Mon', 2, 'Tue', 3] The tuple is : ('Mon', 2, 'Tue', 3)
With *
We can apply the * operator we can expand the given list and put the result in a parentheses.
Example
listA = ["Mon",2,"Tue",3] # Given list print("Given list A: ", listA) # Use zip res = (* listA,) # Result print("The tuple is : ",res)
Output
Running the above code gives us the following result −
Given list A: ['Mon', 2, 'Tue', 3] The tuple is : ('Mon', 2, 'Tue', 3)
- Related Questions & Answers
- How to convert a list into a tuple in Python?
- Convert a list into tuple of lists in Python
- Convert set into a list in Python
- Convert a nested list into a flat list in Python
- How to convert JSON data into a Python tuple?
- How I can convert a Python Tuple into Dictionary?
- Python program to convert Set into Tuple and Tuple into Set
- Convert a string representation of list into list in Python
- How to convert python tuple into a two-dimensional table?
- Convert a Set into a List in Java
- Python - Convert given list into nested list
- How can I convert Python strings into tuple?
- Convert list into list of lists in Python
- Convert list of tuples into list in Python
- Python program to convert a list of characters into a string
Advertisements