Very well done! The
zip() function also works fine when the lists are of different sizes. Take a look:
cars_dealer_a = [13000, 12300, 18900, 34500, 23900]
cars_dealer_b = [14000, 12000, 19000]
for car in zip(cars_dealer_a, cars_dealer_b):
if car < car:
print('Dealer A is cheaper by', car - car)
elif car < car:
print('Dealer B is cheaper by', car - car)
In the example above,
cars_dealer_a now contains five elements, while
cars_dealer_b has three elements; still, the code works in the same way. This is because
zip() automatically finds the list with the smaller number of elements, in other words, it stops when a zip element (teeth) is missing. In the example above, the additional two elements in
cars_dealer_a are simply ignored.
If for some reason you want to iterate over the longer list, you need to use another method –
zip() won't work in that case.