The code loops through word
with a step size of 3 and groups every 3 consecutive words.
Let’s say word = [1, 2, 3, 4, 5, 6, 7, 8, 9]
Over the course of the loop, i
will be = 0, 3, 6
To grid
, you append word[0:3]
,word[3:6]
,word[6:9]
So grid
will have in it [[1,2,3],[4,5,6],[7,8,9]]
for x,y,z in grid:
print(x,y,z)
This just prints the contents. Each element on a separate line.
I feel that running the code will tell you what’s happening. Or were you wondering how it works (e.g. list comprehension).
1
solved What does this piece of code mean?