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}]
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])))
a = [{"date":[14,2,2020],"stockValue":-0.57357144},{"date":[9,2,2020],"stockValue":-0.66407406},{"date":[10,2,2020],"stockValue":-0.62166667}]
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])))