Skip to content

Dynamically iterate over multiple lists in Python using while loop

pokemon = ['pikachu', 'charmander', 'squirtle', 'bulbasaur']
types = ['electric', 'fire', 'water', 'grass']
levels = [16, 11, 9, 12]
poke_info = [pokemon, types, levels]
index = 0
while all(index < len(row) for row in poke_info):
  curr_pokemon = pokemon[index]
  curr_type = types[index]
  curr_level = levels[index]
  index += 1

Source

See also  How to print in Java?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.