Sorting list of lists by a third list of specified non-sorted order

前端 未结 3 1380
我寻月下人不归
我寻月下人不归 2021-01-06 06:18

I have a list:

[[\'18411971\', \'kinase_2\', 36], [\'75910712\', \'unnamed...\', 160], ...
  • about 60 entries long
  • each entry
3条回答
  •  生来不讨喜
    2021-01-06 06:56

    So, if I understand you right, you have your sample input list:

    a = [['18411971', 'kinase_2', 36], ['75910712', 'unnamed...', 160], ...
    

    and you want to sort this using an extra list that mentions the order in which the first elements of the sub-lists are to occur in the output:

    aux = ['75910712', '18411971', ...]
    

    If that's right, I think the result can be achieved using something like:

    sorted(a, key = lambda x: aux.index(x[0]))
    

提交回复
热议问题