I donot understand how to interpret this question . | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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]

21st Oct 2020, 12:56 PM
Curious Ant
Curious Ant - avatar
2 Answers
+ 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.
21st Oct 2020, 1:35 PM
Lothar
Lothar - avatar
+ 2
Think of zip like 2 for loops running in parallel, so it will return the 9th items of both sequences.
21st Oct 2020, 1:02 PM
QTWizard