A
A
Alexander Pikeev2020-08-04 19:12:11
Python
Alexander Pikeev, 2020-08-04 19:12:11

Passage at once on two lists?

Is there any way to loop through two lists at once?
By type: (this will not work). for i, j in digits, symbols

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Evgeny Shatunov, 2020-08-04
@Baryon

There is a built-in function for this zip[ ? ].

for digit, symbol in zip(digits, symbols):
  pass

A
AlexBoss, 2020-08-05
@AlexBoss

zip will truncate a list that is longer.
Why not make it explicit?

for i in range(max(len(digits), len(symbols))):
  try:
    print(digits[i], symblos[i])
...

And then process the list, which is as long as you like

P
PavelMos, 2020-08-04
@PavelMos

most likely in no way, only by realizing the connection of one with the other. That is, if i=1,2,3 and j='a','b','c' then make a dictionary of matches first

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question