mylist = [ [2,4,1], [1,2,3], [2,3,5] ]
a=0
b=0
total = 0
while a <= 2:
while b < 2:
total += mylist[a][b]
b += 1
a += 1
b = 0
print (total)
I don't understand what mylist[a][b]
does.
I tried adding print statements and checked each of the outputs, but I still can't figure out what it does.
The output with print statement I got was: (each printed output every time it goes through the loop:)
2
4
1
2
2
3
(total)
14
I thought each output were the items inside the lists in mylist
, but realized it's not. I also tried changing the numbers inside the lists, I still don't understand. Can someone simply explain it to me please?