Sorting list based on values from another list?

后端 未结 15 2622
温柔的废话
温柔的废话 2020-11-21 07:14

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 ]
         


        
15条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-21 08:06

    Another alternative, combining several of the answers.

    zip(*sorted(zip(Y,X)))[1]
    

    In order to work for python3:

    list(zip(*sorted(zip(B,A))))[1]
    

提交回复
热议问题