I have a list of lists. For example,
[
[0,1,'f'],
[4,2,'t'],
[9,4,'afsd']
]
If I wanted to sort the outer list by the string field of the inner lists, how would you do that in python?
I have a list of lists. For example,
[
[0,1,'f'],
[4,2,'t'],
[9,4,'afsd']
]
If I wanted to sort the outer list by the string field of the inner lists, how would you do that in python?
More easy to understand (What is Lambda actually doing):
I think lambda function can solve your problem.
You can easily sort using this snippet, where 1 is the index of the element.
This is a job for itemgetter
It is also possible to use a lambda function here, however the lambda function is slower in this simple case
in place
not in place using sorted:
multiple criteria can also be implemented through lambda function