Python的列表还可以嵌套。

以下实例展示了3X4的矩阵列表:

python3嵌套列表解析_Python
以下实例将3X4的矩阵列表转换为4X3列表:

python3嵌套列表解析_Python_02
以下实例也可以使用以下方法来实现:
python3嵌套列表解析_Python_03
python3嵌套列表解析_Python_04
另外一种实现方法:

>>> transposed = []
>>> for i in range(4):
...     # the following 3 lines implement the nested listcomp
...     transposed_row = []
...     for row in matrix:
...         transposed_row.append(row[i])
...     transposed.append(transposed_row)
...
>>> transposed
[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]