小编Shi*_*ngh的帖子

在python中将矩阵的上三角形部分显示为列表的有效方法

考虑以下结构 -

68 69 70 71 72 *
73 74 75 76 * 77
78 79 80 * 81 82
83 84 * 85 86 87 
88 * 89 90 91 92
* 93 94 95 96 97
Run Code Online (Sandbox Code Playgroud)

我必须生成一个上半部分列表即

[68, 69, 70, 71, 72, 73, 74, 75, 76, 78, 79, 80, 83, 84, 88]
Run Code Online (Sandbox Code Playgroud)

该结构仅用于解释,只给出了两个值,即开始和长度,如上例start=68length = 5.

这是我生成列表的代码 -

start = 68
length = 5

ls = []
for i in range(length):
    for j in range(length-i): …
Run Code Online (Sandbox Code Playgroud)

python performance time-complexity

0
推荐指数
1
解决办法
226
查看次数

标签 统计

performance ×1

python ×1

time-complexity ×1