Search code examples
pythonarrayslistfor-loopcounter

How to count 2 lists in parallel in Python?


I have two lists.

Numbers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
Letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

I want to count these two lists in parallel. When the next value is selected in one list, the next value is selected in another list too.

Like this:

Number: 1, Letter: a
Number: 2, Letter: b
Number: 3, Letter: c
Number: 4, Letter: d
Number: 5, Letter: e
Number: 6, Letter: f

and so on. How can I do this?


Solution

  • Pythonic way

    for x,y in  zip(Numbers,Letters ):
        print(f"Number{x},Letter{y}")