Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
>>> l = [{'name': 'C', 'price': 5}, {'name': 'A', 'price': 2}, {'name': 'B', 'price': 1}]
>>> newlist = sorted(l, key=lambda k: k['price'])
>>> newlist
[{'name': 'B', 'price': 1}, {'name': 'A', 'price': 2}, {'name': 'C', 'price': 5}]
>>> from operator import itemgetter
>>> newlist = sorted(l, key=itemgetter('price'))
>>> newlist
[{'name': 'B', 'price': 1}, {'name': 'A', 'price': 2}, {'name': 'C', 'price': 5}]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question