Python - Iterate over multiple lists simultaneously with zip


Python tip:

You can use zip to iterate through multiple lists of equal length in a single loop.

👇

users = ["Jan", "Mike", "Marry", "Mike"]
user_visits = [10, 31, 10, 1]

for user, visits in zip(users, user_visits):
    print(f"{user}: {visits}")

# Jan: 10
# Mike: 31
# Marry: 10
# Mike: 1