Sort this list on the basis of date(in increasing order) (in python)

Question:

a = [{"date":[14,2,2020],"stockValue":-0.57357144},{"date":[9,2,2020],"stockValue":-0.66407406},{"date":[10,2,2020],"stockValue":-0.62166667}]
Asked By: photonboost

||

Answers:

from datetime import datetime
a = [{"date":[14,2,2020],"stockValue":-0.57357144},{"date":[9,2,2020],"stockValue":-0.66407406},{"date": [10,2,2020],"stockValue":-0.62166667}]

print(sorted(a, key=lambda x: datetime(year=x["date"][2], month=x["date"][1], day=x["date"][0])))
Answered By: maya
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.