Here we are using .zip () to iterate over multiple lists at the same time. Zip () takes n iterations and returns a list of tuples. The i-th element of the tuple is created using the i-th element of each iteration.
L1 = [1,2,3,4] L2 = [`aa`, `bb`, `cc`, `dd`] L = zip (L1, L2) Output [(1, `aa`), (2, `bb`), (3, `cc`), (4, `dd`)]
Step 1: first create 3 user input list. Step 2: use .zip () function. Step 3: print tuples.
# To iterate over 3 lists using zip function importitertools A = list () B = list () C = list () n = int (input ("How many you data want to store ??")) print ("Enter Roll no.") For i in range (int (n)): k = int (input ( "")) A.append (k) print ("Enter Name ::") for j in range (int (n)): k1 = input ("") B.append (k1) print ("Enter Age :: ") for j in range (int (n)): k1 = int (input (" ")) C.append (k1) print (" iterating using zip ") for (a, b, c) in zip (A, B, C): print (a, b, c)
How many you data want to store? ? 4 Enter Roll no. 56 89 67 34 Enter Name :: yui jkl vm dfg Enter Age :: 7 9 6 5 iterating using zip 56 yui 7 89 jkl 9 67 vm 6 34 dfg 5
< / p>
Computer languages have so far been of the ‘interpreted’ or the ‘compiled’ type. Compiled languages (like ‘C’) have been more common. You prepare a program, save it (the debugged version),...
In Learn Python 3 the Hard Way PDF, you'll learn Python by working through 52 brilliantly crafted exercises. Read them. Enter your code exactly. (No copying and pasting!) Correct your mistakes. ...
Executing Data Quality Projects: Ten Steps to Quality Data and Trusted Information (TM), 2nd Edition. Execute Data Quality Projects, Second Edition presents a structured yet flexible approach to cr...
Deep Learning for Coders with fastai and PyTorch: AI Applications Without a PhD. Deep learning is often seen as the exclusive domain of math PhDs and big tech companies. But as this how-to guide sh...