Return Python 列表中每个子列表的大于 k 的数字索引
Return index of numbers greater than k for each of sublists in list in Python
输入:
在子列表中查找大于 50 的数字索引
a = [[10,40,90],[120,30,200],[70,90,100]]
期望的输出:
index_of_values_greater_than_50 = [[2][0,2][0,1,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]]
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)
输入: 在子列表中查找大于 50 的数字索引
a = [[10,40,90],[120,30,200],[70,90,100]]
期望的输出:
index_of_values_greater_than_50 = [[2][0,2][0,1,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]]
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)