DEV Community

Kozo Oeda
Kozo Oeda

Posted on • Edited on

How to get access in a list of tuples with ordered numbers in a for-loop

I encountered a situation where I needed to use elements from a list of tuples with ordered numbers, and it worked.

example_list = [("a", "b"), ("c", "d"), ("e", "f"), ("g", "h"), ("i", "j")]

for num, (el1, el2) in enumerate(example_list):
    print(num, el1, el2)
Enter fullscreen mode Exit fullscreen mode

Result:


 0 a b
 1 c d
 2 e f
 3 g h
 4 i j

Enter fullscreen mode Exit fullscreen mode

Version: Python 3

Top comments (0)