0
I donot understand how to interpret this question .
Which of the options passed to "print" in order ( 9,9) to be displayed ? a= range (10) b = range( 20 ) answer is list(zip(a,b))[9]
2 odpowiedzi
+ 6
just to remember that zip() will only run according the length of the "shortest" sequence. (a is shorter than b). if also the items of the longest sequence are required, function zip_longest() can be used.
a = range(10)
b = range( 20)
c = range(13)
from itertools import zip_longest
for temp in list(zip_longest(a, b, c, fillvalue=-1)):
print(temp)
There is an additional parameter "fillvalue" that can be used to define the value that has to replace the missing values in the shorter sequences.
+ 2
Think of zip like 2 for loops running in parallel, so it will return the 9th items of both sequences.