[Fixed]-How to sort a list or dictionary in django?

1👍

✅

First of all you should consider renaming your variable dictionary to something that resembles a list. Now, I am assuming that you want to sort your dictionary by price. If that is correct you can use following:

dictionary = sorted(dictionary, key=lambda x:x['price'])

This will be in ascending order of price, to make it descending use

dictionary = sorted(dictionary, key=lambda x:x['price'], reverse=True)

Leave a comment