Convert tuple to list and back
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
In Python, converting between tuples and lists is done with the built-in list() and tuple() constructors. list(my_tuple) creates a mutable list from a tuple, and tuple(my_list) creates an immutable tuple from a list. This is a common operation when you need to modify a sequence that was returned as a tuple, or when you need to use a sequence as a dictionary key (which requires immutability).
Tuple to List
List to Tuple
Common Use Case: Modify a Tuple
Since tuples are immutable, the only way to "modify" one is to convert to a list, make changes, and convert back:
Nested Tuples and Lists
list() and tuple() only convert the outermost level. Nested structures keep their original types:
Converting for Dictionary Keys
Tuples can be dictionary keys because they are hashable (if their contents are hashable). Lists cannot:
Converting for Function Arguments
Use * to unpack a list or tuple as function arguments:
Performance Comparison
Tuples use slightly less memory than lists because they are fixed-size:
Working with Named Tuples
Common Pitfalls
- Assuming conversion is deep:
list(((1,2), (3,4)))gives[(1,2), (3,4)]— inner tuples remain tuples. For full conversion of nested structures, use a recursive function or list comprehension. - Modifying the converted list affects nothing:
list(my_tuple)creates a new list. Changing the list does not affect the original tuple (and vice versa). They are independent copies (shallow copy). - Using lists as dictionary keys or set elements: Lists are unhashable and cannot be used as dictionary keys or in sets. Convert to tuples first:
my_set.add(tuple(my_list)). - Forgetting single-element tuple syntax:
(1)is not a tuple — it is the integer1in parentheses. A single-element tuple requires a trailing comma:(1,).list((1,))gives[1], butlist((1))raisesTypeError. - Performance with large sequences: Both
list()andtuple()copy every element, which is O(n). For very large sequences, avoid unnecessary back-and-forth conversion. If you need mutability, keep the data as a list throughout.
Summary
list(my_tuple)converts a tuple to a mutable list;tuple(my_list)converts back- Conversion is shallow — nested structures retain their original types
- Use list conversion when you need to modify an immutable tuple
- Use tuple conversion when you need a hashable sequence (dictionary keys, set elements)
- Both operations are O(n) and create independent copies (shallow)
- Single-element tuples require a trailing comma:
(value,)
Related reading
- Converting a 2D grid graph data structure to a tree
- Converting a heap to a BST in On time?
- Converting a list of unequally shaped arrays to Tensorflow 2 Dataset ValueError Can't convert non-rectangular Python sequence to Tensor
- Converting a list to a set changes element order
- Convert Unicode to ASCII without errors in Python
- Convert unix time to readable date in pandas dataframe
- Converting array to list in Java
- Converting ''ArrayList<String> to ''String[]'' in Java

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.