0
Can anyone explain above code???
primary = { "red": [255, 0, 0], "green": [0, 255, 0], "blue": [0, 0, 255], } for i, j in primary.items(): print(i,j[0],j[1],j[2]) Output: red 255 0 0 green 0 255 0 blue 0 0 255 >
1 ответ
+ 3
It prints the key and then each item inside the list or value of that key.
primary.items() returns a tuple of key-value pair
🔹(key, value).
So for every iteration:
🔹i ---> key
🔹j ---> value
Then it prints the key, the value (first, secon], third indexes), since the value are lists.
For better understanding, here is a snippet with more meaningful variables.
_____________________________
for key, val in primary.items():
print(key, val[0], val[1], val[2])
_____________________________