Loops 16/19 ..Multiple lists - why?

list_a = [3, 9, 17, 15, 19]
list_b = [2, 4, 8, 10, 30, 40, 50, 60, 70, 80, 90]

for a, b in zip(list_a, list_b):
  # Add your code here!
  if a > b :
    print a
    print b

everything is working but i just can’t understand why it prints only 5 values… 3 9 17 15 30
but it doesn`t continue with list_b ? how i get it if there is nothing in list_a it should be 0 so … and print the rest of list_b ??!


When we zip two uneven lists, only the smaller of the two is given consideration.

(3,2), (9,4), (17,8), (15,10), (19,30)

  a      a       a       a        b


A 0 is not the same thing as the absence of a value. Consider a scenario where two teams are counting elephant populations, for example, and they each record a count for every day that they go out to take a survey. If one team goes out 5 times and the other one 11, padding the shorter list with sufficient 0s to make them of equal length might imply that the first team counted 0 elephants on 6 days during which they actually did not go out at all.

In any case, since 0 could be a valid data value, the the zip function is designed such that it does not pad the shorter sequence with trailing 0s.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.