1

Let's say, I have two lists

id = [4,3,1,2],  
nm = ['d','c','a','b']

I want to bind indexes of both lists in such way, that if I sort the list 'id' :

id = sorted(id)

then, the list 'nm' must change according to indexes of list 'id' i.e.

id = [1,2,3,4],  
nm = ['a','b','c','d']

I have tried to bind lists using zip,

for i, n in zip(id,nm):
    name.append(n)
print(name)

but this will give me result of original 'nm' list.

Do I need to change something and play more with zip?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Kabs
  • 23
  • 3

0 Answers0