如何使用if语句检查列表中的特定值是否等于另一个列表中的值? [英] How to check if a particular value in a list is equal to a value in another list using if statement?
问题描述
如果
a = [1,2,3,4,5]
b = [6,7,8,5,9]
如何检查[4] = a [3]?
我应该写什么代码,如果它应该是真的?
这是我的代码。
----------------------------
if
a=[1,2,3,4,5]
b=[6,7,8,5,9]
how to check if a[4]=a[3]?
what code should i write if it should be true?
This is the code i have made.
----------------------------
dict={}
a=[1,2,3,4,3,1,2,8,9,10]
b=[]
b+=a
for i in a:
for j in b:
dict[a[i]]=j
print(min(dict,key=dict.get))
我的尝试:
我用它来找到具有最小索引的重复值。
但是如果声明剂量有效。为什么?
What I have tried:
I have used this to find the duplicate value with the minimum index.
but if statement dosent work. why is it?
dict={}
a=[1,2,3,4,3,1,2,8,9,10]
b=[]
b+=a
for i in a:
for j in b:
dict[a[i]]=j
print(min(dict,key=dict.get))
推荐答案
但是如果声明剂量有效。为什么?
but if statement dosent work. why is it?
显而易见!正如 Richard MacCutchan [ ^ ]在问题的评论中提到,没有 if 你的代码中的code>语句!
回到基础知识: Python - 数组 [ ^ ]
Python IF ... ELIF ... ELSE语句 [ ^ ]
It's obvious! As Richard MacCutchan[^] mentioned in the comment to the question, there's no if
statement in your code!
Go back to basics: Python - Arrays[^]
Python IF...ELIF...ELSE Statements[^]
还看看at:在列表中查找重复的数字| GeoNet [ ^ ]。
这篇关于如何使用if语句检查列表中的特定值是否等于另一个列表中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!