Jul-19-2019, 11:28 PM
Hi,
I'm really struggling in understanding how parallel iteration works with for loops.
Here is just some experimental code:
The for loops with the i,j,k and i,j is where my understanding breaks down...
It's clearly iterating 3 times because it's printing 3 times..
My tired neurons can't figure out what's happening this late. Someone explain please
I'm really struggling in understanding how parallel iteration works with for loops.
Here is just some experimental code:
myList = list(zip(['a', 'b', 'c'],['abc', 'def', 'ghi'],[1, 2, 3]))
print(myList)
for i in myList:
print(i)
for i,j,k in myList:
print(i,j,k)
for i,j,k in myList:
print(i,j)
for i,j in myList:
print(i,j,k)Output:[('a', 'abc', 1), ('b', 'def', 2), ('c', 'ghi', 3)]
('a', 'abc', 1)
('b', 'def', 2)
('c', 'ghi', 3)
a abc 1
b def 2
c ghi 3
a abc
b def
c ghi
ValueError: too many values to unpack (expected 2)I understand the first print statement and the first for loop.The for loops with the i,j,k and i,j is where my understanding breaks down...
It's clearly iterating 3 times because it's printing 3 times..
My tired neurons can't figure out what's happening this late. Someone explain please
