To create a three-dimensional list in Python, you can use nested lists where each inner list represents a 2D plane within the 3D space.
In this example,
matrix_3d = [[[i + j + k for k in range(3)] for j in range(3)] for i in range(3)]
print(matrix_3d)
[[[0, 1, 2], [1, 2, 3], [2, 3, 4]], [[1, 2, 3], [2, 3, 4], [3, 4, 5]], [[2, 3, 4], [3, 4, 5], [4, 5, 6]]]
In this example,
matrix_3d = [[[(f'({i}, {j}, {k})') for k in range(2)] for j in range(2)] for i in range(2)]
print(matrix_3d)
[[['(0, 0, 0)', '(0, 0, 1)'], ['(0, 1, 0)', '(0, 1, 1)']], [['(1, 0, 0)', '(1, 0, 1)'], ['(1, 1, 0)', '(1, 1, 1)']]]
In this tutorial, we learned How to create a Three Dimensional List in Python language with well detailed examples.