3

I am wondering if it's posiible to iterate over two lists at once.
Something like that:

for x, m in list1, list2:
    ...

I know that I should use the '.items()', but I don't want to create dictionary from two lists.
Any ideas?

R.O.S.S
  • 605
  • 5
  • 18

1 Answers1

2

Use zip.

for x, m in zip(list1, list2):

zip(*iterables)

Make an iterator that aggregates elements from each of the iterables.

Returns an iterator of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables. The iterator stops when the shortest input iterable is exhausted. With a single iterable argument, it returns an iterator of 1-tuples. With no arguments, it returns an empty iterator.

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274