I have a list
in python
as follows,
l = [['4K', ['read', '10'], ['rand', '70']],
['64K', ['read', '15'], ['rand', '0']],
['64K', ['read', '0'], ['rand', '0']],
['4K', ['read', '60'], ['rand', '100']],
['4K', ['read', '50'], ['rand', '0']]]
If temp = ['4K', ['read', '10'], ['rand', '100']
I first want to sort based on temp[2][1]
, after which I want to sort the list further without modifying the previous sort with respect to temp[1][1]
. I want the end result to be something like follows,
res = [['64K', ['read', '0'], ['rand', '0']],
['64K', ['read', '15'], ['rand', '0']],
['4K', ['read', '50'], ['rand', '0']],
['4K', ['read', '10'], ['rand', '70'],
['4K', ['read', '60'], ['rand', '100']
]
In res
above the priority is first given to rand
which is sorted first, after which read
is sorted with the sorted rand
. I have tried things like l.sort(key=lambda x: int(x[2][1]))
which first sorts the rand
, but sorting the same l
further does not give expected output as the previous sort is not remembered. Is there an easy way to do this? Or is the only way to this would be to split the list further with same rand
and then sort and merge all together at the end?