Convert tuple to list and back
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
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,)

