在 python 中的每个列表列表中移动特定值(基于该值)

move specific values (based on that value) in each list of lists in python

我有一个列表列表,如下所示:

list= [[0,1,0,0,0][0,0,0,2,0],...,[0,0,10,0,0]]

我想要的输出是将所有值 (1,2..,10) 移动到它们所在列表的开头,所以类似于 :

list= [[1,0,0,0,0][2,0,0,0,0],...,[10,0,0,0,0]]

我试过了:

new_list= list.insert(0, list.pop(list.index(value)))

这适用于一个列表,但我想对列表中的所有列表都这样做。

您可以排序:

l = [[0,1,0,0,0],[0,0,0,2,0],[0,0,10,0,0]]
print([sorted(i, reverse=True) for i in l])

输出:

[[1, 0, 0, 0, 0], [2, 0, 0, 0, 0], [10, 0, 0, 0, 0]]