+ 1
How to print corresponding value of list2 in list1 when I have duplicate values?
I am done with the logic but my code prints only for 1st occuring index. l=[10,36,54,89,12,17] m=[3,7,3,0,7,0] res=sorted(m) for i in res: print(l[m.index(i)],i) I need 89 0 17 0 10 3 54 3 12 7 36 12 but my output is 89 0 89 0 10 3 10 3 36 7 36 7 help me out plz
11 Answers
+ 2
uma
Sry for late response, Iam not good at python but got this way finally....
This works..(from list no element is perfect actually, is it OK?)..
(printing without sort, since res have dublicates)
for i in range(len(m)):
print(l[i],m[i])
Next, by zip sorting
n=list(zip(m,l))
n=sorted(n)
for i in range(len(n)) :
print(n[i])
I got this way...
But working to get as required way...
Edit:
Oma Falk thanks for that sorting key..
Finally got this way..
https://code.sololearn.com/cDq7E36wD021/?ref=app
+ 1
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥
https://code.sololearn.com/cuYhNSAybtfW/?ref=app
I need it in order of occurrence
But it is sorted by m
0
I've now edited so that u can understand. Jayakrishna🇮🇳
0
I want to print corresponding value of elements of elements in L with respect to elements in res
0
Thanks Oma Falk
0
uma
you need a sort key in your solution
d=sorted(c,key = lambda x: (x[0],a.index(x[1])) )
0
Jayakrishna🇮🇳
for el in n:
print(*el)
0
Thanksss Jayakrishna🇮🇳
- 1
Can you explain the logic bit more..
Edit : OK. thanks for edit.......