Skip to content

Dynamically iterate over multiple lists in Python using zip

pokemon = ['pikachu', 'charmander', 'squirtle', 'bulbasaur']
types = ['electric', 'fire', 'water', 'grass']
levels = [16, 11, 9, 12]
poke_info = [pokemon, types, levels]
for sublist in zip(*poke_info):
  poke, t, level = sublist
  # Do something with these variables

Source

See also  How To target a particular td in CSS?

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.