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 ]
I actually came here looking to sort a list by a list where the values matched.
list_a = ['foo', 'bar', 'baz'] list_b = ['baz', 'bar', 'foo'] sorted(list_b, key=lambda x: list_a.index(x)) # ['foo', 'bar', 'baz']