'Sort list containing dictionary according to date [duplicate]
I want to sort the below-provided list based on the 'date' value using DSA and not any external/internal modules in Python. I tried but am unable to come up with any working solution here. Kindly help me with that.
a = [{"date":[14,1,2020],"stockValue":-0.57357144},
{"date":[9,2,2021],"stockValue":-0.66407406},
{"date":[10,2,2020],"stockValue":-0.62166667}]
The expected answer will be as below.
a = [{"date":[14,1,2020],"stockValue":-0.57357144},
{"date":[10,2,2020],"stockValue":-0.62166667},
{"date":[9,2,2021],"stockValue":-0.66407406}]
Solution 1:[1]
a.sort(key=lambda x: x['date'], reverse=True)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | eshirvana |
