-1

I am searching for a function that can apply position changes in a list to other lists. For example:

liste1 = [3, 4, 1] 
liste2 = ['a', 'b', 'c']
liste1.sort()   #so liste1 = [1,3,4]
if liste1 = [1,3,4] :
   liste2 = ['c', 'a', 'b']

I can change positions of liste2 myself, but I have 270,000 values, which is why I am searching for a function that can do it.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

1

You could zip the lists together, sort them then unzip them.

liste1 = [3, 4, 1] 
liste2 = ['a', 'b', 'c']
merged_lists = sorted(zip(liste1, liste2))
liste1, liste2 = zip(*merged_lists)
print(liste1, liste2, sep="\n")

OUTPUT

(1, 3, 4)
('c', 'a', 'b')
Chris Doyle
  • 10,703
  • 2
  • 23
  • 42