How to iterate through list of tuples in Python
Last Updated :
23 Jul, 2025
In Python, a list of tuples is a common data structure used to store paired or grouped data. Iterating through this type of list involves accessing each tuple one by one and sometimes the elements within the tuple. Python provides several efficient and versatile ways to do this. Let’s explore these methods
Using a for Loop
A basic for loop allows us to iterate through the list and access each tuple directly. It is Ideal for straightforward traversal when the entire tuple is needed.
Python
x = [(1, 'a'), (2, 'b'), (3, 'c')]
# Iterate through the list and print each tuple
for tup in x:
print(tup)
Output(1, 'a')
(2, 'b')
(3, 'c')
Let's explore some other methods on how to iterate through a list of tuples in Python
Using enumerate()
enumerate()function adds an index to each tuple making it easier to track their positions in the list. The enumerate() function returns both the index and the tuple in each iteration. It is Ideal when the index of each tuple is required along with its value.
Python
x = [(1, 'a'), (2, 'b'), (3, 'c')]
# Iterate through the list with index and tuple
for idx, tup in enumerate(x):
print(f"Index: {idx}, Tuple: {tup}")
OutputIndex: 0, Tuple: (1, 'a')
Index: 1, Tuple: (2, 'b')
Index: 2, Tuple: (3, 'c')
Using List Comprehension
For compact code, list comprehension can be used to iterate and perform operations on each tuple. It is best for creating new lists based on operations on tuples.
Python
x = [(1, 'a'), (2, 'b'), (3, 'c')]
# unpack the tuple into num and char
#format the result as "num-char"
result = [f"{num}-{char}" for num, char in x]
print(result)
Output['1-a', '2-b', '3-c']
Using a while Loop with Indexing
A while loop can iterate through a list of tuples by tracking the index. The while loop provides complete control over the iteration process. It is useful when we need to modify the index dynamically during iteration.
Python
x = [(1, 'a'), (2, 'b'), (3, 'c')]
i = 0
while i < len(x):
print(x[i])
i += 1
Output(1, 'a')
(2, 'b')
(3, 'c')
Explore
Python Fundamentals
Python Data Structures
Advanced Python
Data Science with Python
Web Development with Python
Python Practice