Rearranging list based on order of another list

try to use key with sorted:

sorted(_list2,key=_list1.index)

for nested list you can use list comphresnion:

[sorted(x,key=_lis1.index) for x in _list2]

Leave a Comment