輸入:查找子列表中大于 50 的數(shù)字的索引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條經(jīng)驗 獲得超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)
輸出(根據(jù)需要):
[[2], [0, 2], [0, 1, 2]]

慕少森
TA貢獻2019條經(jīng)驗 獲得超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
提交
取消