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 ]
You can create a pandas Series, using the primary list as data and the other list as index, and then just sort by the index:
pandas Series
data
index
import pandas as pd pd.Series(data=X,index=Y).sort_index().tolist()
output:
['a', 'd', 'h', 'b', 'c', 'e', 'i', 'f', 'g']