I have a list of strings like this:
X = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\"] Y = [ 0, 1, 1, 0, 1, 2, 2, 0, 1 ]
more_itertools has a tool for sorting iterables in parallel:
Given
from more_itertools import sort_together X = ["a", "b", "c", "d", "e", "f", "g", "h", "i"] Y = [ 0, 1, 1, 0, 1, 2, 2, 0, 1]
Demo
sort_together([Y, X])[1] # ('a', 'd', 'h', 'b', 'c', 'e', 'i', 'f', 'g')