zip to iterate over pairs of lists

PHOTO EMBED

Thu Sep 16 2021 14:51:53 GMT+0000 (UTC)

Saved by @zeroxenator

list_of_letters = ["A", "B", "C"]
list_of_ids = [1, 2, 3]

# bad practice 

for i in range(len(list_of_letters)):
    letter = list_of_letters[i]
    id_ = list_of_ids[i]
    process_letters(letter, id_)
		
# good practice

# list(zip(list_of_letters, list_of_ids)) = [("A", 1), ("B", 2), ("C", 3)]

for letter, id_ in zip(list_of_letters, list_of_ids):
    process_letters(letter, id_)
content_copyCOPY