Multi List Iteration with Zip
Simplify Iterating Over Multiple Lists With Zip()
Before
names = ['Nik', 'Jane', 'Melissa', 'Doug']
ages = [32, 28, 37, 53]
gender = ['Male', 'Female', 'Female', 'Male']
for_looped = []
for i in range(len(names)):
for_looped.append((names[i], ages[i], gender[i]))
print(for_looped)
After
names = ['Nik', 'Jane', 'Melissa', 'Doug']
ages = [32, 28, 37, 53]
gender = ['Male', 'Female', 'Female', 'Male']
zipped = zip(names, ages, gender)
zipped_list = list(zipped)
print(zipped_list)