Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
----------------------------
Python
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?

Python
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))
Posted
Updated 7-Jun-18 1:59am
v3
Comments
Patrice T 6-Jun-18 18:03pm    
If you want an explanation of the reason why your 'if' fail, you need to show that code. We can'r guess what you did wrong.
details on what you had in mind may help us to understand what was wrong.
Otherwise, this is a good tutorial site: Python Tutorial[^]
Member 13861803 6-Jun-18 20:03pm    
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))

This is the code i made. is there anything wrong with the code?
Richard MacCutchan 7-Jun-18 4:14am    
Well the obvious question from that is, "does it do what you expect"? And since there is no if statement in there, how does it relate to your question?
Maciej Los 7-Jun-18 6:50am    
My virtual 5!
Patrice T 7-Jun-18 17:42pm    
++

but if statement dosent work. why is it?

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[^]
 
Share this answer
 
Comments
CPallini 7-Jun-18 7:59am    
5.
Maciej Los 7-Jun-18 8:28am    
Thank you, Carlo!
 
Share this answer
 
Comments
Maciej Los 7-Jun-18 8:27am    
5ed!
CPallini 7-Jun-18 8:37am    
Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900