12

I have a list of dictionaries like this but with many more dictionaries:

x = [{"duration":datetime.time(5,30),"date":datetime.date(2016,02,13)},{"duration":datetime.time(3,30),"date":datetime.date(2016,02,11)},{"duration":datetime.time(2,0),"date":datetime.date(2016,02,16)}]

Is there a way to sort this list in ascending order of date using Python keywords such as sorted and lambda without making a custom sorting function? I have been looking at the sorted docs and the use of lambda in the optional key argument.

Rob Murray
  • 1,773
  • 6
  • 20
  • 32

1 Answers1

6

While posting the question I figured out the answer so thought I should share.

x = sorted(x, key = lambda k: k["date"])
Rob Murray
  • 1,773
  • 6
  • 20
  • 32