DEV Community

Kozo Oeda
Kozo Oeda

Posted on

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

I faced a case to use elements in a list of tuples with ordered numbers. And it works.

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

for num, (el1, el2) in enumerate(example_list):
    print(num, el1, el2)

Result:


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

Version: Python 3

Top comments (0)