如何获取二维列表斜对角上的数据
>>> matrix = [,,
]
>>> diag = for i in range(len(matrix))]
>>> diag
从左到右的对角数据会获取,从右到左的怎么办
{:9_241:} matrix = [,
,
]
l = len(matrix)
diag = for i in range(l)]
print(diag) diag = for i in range(len(matrix))] tommyyu 发表于 2022-8-15 13:08
谢谢了 tommyyu 发表于 2022-8-15 13:08
>>> diag = for i in range(len(matrix))]
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
diag = for i in range(len(matrix))]
File "<pyshell#1>", line 1, in <listcomp>
diag = for i in range(len(matrix))]
IndexError: list index out of range tommyyu 发表于 2022-8-15 13:08
错了吧,3-i-1吧 九歌当下 发表于 2022-8-15 13:21
{:10_266:} 写错了,是3-i-1 diag = ] for i in range(len(matrix))] tommyyu 发表于 2022-8-15 13:39
写错了,是3-i-1
好的,谢谢了{:10_256:}
页:
[1]