[英]Determining inequality through lists
嘗試運行循環以確定list1 [0]是否小於list2 [0],依此類推。 如果條件為真,我想捕獲列表索引。
list1 = [1, 2, 3, 4, 5]
list2 = [2, 3, 4, 1, 6]
masterlist = [list1, list2]
for run in masterlist[0]:
if run < masterlist[1]:
#value = true
>>> next((el[0] for el in enumerate(zip(list1, list2)) if el[1][0] < el[1][1]), None)
0
>>> [el[0] for el in enumerate(zip(list1, list2)) if el[1][0] < el[1][1]]
[0, 1, 2, 4]
這將起作用:
for index,(value1,value2) in enumerate(zip(list1,list2)):
if value1 < value2:
print index
輸出:
0
1
2
4
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.