亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為 Python 中的列表中的每個子列表返回大于 k 的數字索引

為 Python 中的列表中的每個子列表返回大于 k 的數字索引

躍然一笑 2023-04-18 17:33:30
輸入:查找子列表中大于 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]]   


查看完整回答
反對 回復 2023-04-18
?
慕少森

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)


查看完整回答
反對 回復 2023-04-18
  • 2 回答
  • 0 關注
  • 139 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號