sorting - Sort sublists in a list, Python -
this question has answer here:
i have following list in python upto n:
l = [[x_1,y_1,h_1,w_1], [x_2,y_2,h_2,w_2], ..., [x_n,y_n,h_n,w_n]]
and need sort in descending order respect sum of first , third elements in sublists (x_i , h_i) , first n sublists.
i managed storing sums in new list, there efficient way sort without creating one?
edit: sorry, duplicate question indeed.
go below link , see full detail how sort in python
= sorted(l, key=lambda x: x[0] + x[2])
Comments
Post a Comment