+ 5
python sort function
sub_li =[['rishav', 10], ['akash', 5], ['ram', 20], ['gaurav', 15]] a=sub_li.sort(key = lambda x: x[1]) print(a) why am i getting none as a output not the sorted list why am i getting none when i should get the sorted list
2 odpowiedzi
+ 11
Because the sort() function does not work like this. It actually changes your original list (in-place sorting).
So you can do like:
sub_li.sort()
print(sub_li)
Or:
a = sorted(sub_li)
print(a)
You can use the key parameter with both ways
+ 4
Thanks