fork download
  1. # 3D list representing a cube
  2. cube = [
  3. [[1, 2], [3, 4]], # Layer 1
  4. [[5, 6], [7, 8]] # Layer 2
  5. ]
  6.  
  7. # Accessing an element (Layer 2, Row 1, Column 2)
  8. element = cube[1][0][1]
  9. print("Element at Layer 2, Row 1, Column 2:", element)
  10. # Output: 6
  11.  
  12. # Iterating through the 3D list
  13. for layer in cube:
  14. for row in layer:
  15. for col in row:
  16. print(col, end=' ')
  17. print()
  18. print()
Success #stdin #stdout 0.03s 9580KB
stdin
Standard input is empty
stdout
Element at Layer 2, Row 1, Column 2: 6
1 2 
3 4 

5 6 
7 8