比较列表并返回索引


List1 = ['3','1','2']
List2 = ['0','1','0']
List3 = ['string1','string2','string3']

我想做

 if List1[i] > 3 and List2[i] = 0 # i = iterating through list1/2 at the same time and comparing them
     print(List3[i]) # i = being the index number found when the if statement is met
#expected output = 'string1'

上下文 : https://repl.it/@glasgowm1498/GreenyellowKnowingCommands

我会在zip函数文档中使用python的构建

for item1, item2, item3 in zip(list1, list2, list3):
    if item1 == item2:
        print(item3)

希望对您有所帮助!

相关内容

  • 没有找到相关文章

最新更新