输入:查找子列表中大于 50 的数字的索引a = [[10,40,90],[120,30,200],[70,90,100]]期望的输出:index_of_values_greater_than_50 = [[2][0,2][0,1,2]]
2 回答

慕姐8265434
TA贡献1813条经验 获得超2个赞
output_list = []
a = [[10,40,90],[120,30,200],[70,90,100]]
for array in a:
counter = 0
new_list = []
while counter < len(array):
if array[counter] > 50:
new_list.append(counter)
counter += 1
output_list.append(new_list)
print(output_list)
输出(根据需要):
[[2], [0, 2], [0, 1, 2]]

慕少森
TA贡献2019条经验 获得超9个赞
index_of_values_greater_than_50 = []
for x in a:
temp = [i for i, y in enumerate(x) if (y>50)
index_of_values_greater_than_50.append(temp)
添加回答
举报
0/150
提交
取消