-2

I don't understand what produkt *= y[i][i] mean. I have never seen two [] [] after each other. Please help

x = [1, 2, 3]
y = [x, x, x]
x[1] += 1
y[2] = [4, 4, 4]
x[2] = 0
produkt = 1
for i in range(len(y)):
    produkt *= y[i][i]
print(produkt)
wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • 1
    It means nothing different than usual. You have a list of lists, you get an element, and then you get an element of that list. Do `print(y)` to see the shape of `y` if it helps – Silvio Mayolo May 02 '21 at 19:36
  • 2
    Hint: What is `y[i]`? What is `y[i][i]`? Try adding some `print`s to your loop to show them. – wjandrea May 02 '21 at 19:36
  • @wjandrea thank you, but I have tried to find out what y'[i][i]' means, but I don't understand it. I have never seen two boxes in a row before – Synnøve Bakk May 02 '21 at 19:38
  • 1
    @Synnøve What have you tried exactly? Do you understand what `y[i]` is? If so, think of it as `w = y[i]`. Then what's `w[i]`? – wjandrea May 02 '21 at 19:44
  • 1
    y is a square 2 dimensional list. Iterating through y[i][i] means iterating through the diagonal of that 2d list. – mbostic May 02 '21 at 19:50

1 Answers1

0

This is list of a list or basically a two dimensional list.