0

Given this data model

images = {
    "auto-init-container/auto-init-container": [
        {
            "tag": "c",
            "creation_date": "2020-01-09T21:04:12.351550522Z"
        },
        {
            "tag": "a",
            "creation_date": "2019-05-20T19:52:55.761775039Z"
        },
        {
            "tag": "b",
            "creation_date": "2019-06-20T21:32:44.427162163Z"
        }
    ]
}

How do I sort this in python so that it would sort by latest and get the results below

images = {
    "auto-init-container/auto-init-container": [
        {
            "tag": "c",
            "creation_date": "2020-01-09T21:04:12.351550522Z"
        },
        {
            "tag": "b",
            "creation_date": "2019-06-20T21:32:44.427162163Z"
        },
        {
            "tag": "a",
            "creation_date": "2019-05-20T19:52:55.761775039Z"
        }
    ]
}
fdermishin
  • 3,519
  • 3
  • 24
  • 45
edmamerto
  • 7,605
  • 11
  • 42
  • 66
  • Are you trying to sort by the tag in reversed order? – ssp Dec 13 '20 at 00:35
  • 2
    Does this answer your question? [How do I sort a list of dictionaries by a value of the dictionary?](https://stackoverflow.com/questions/72899/how-do-i-sort-a-list-of-dictionaries-by-a-value-of-the-dictionary) – fdermishin Dec 13 '20 at 00:35
  • Not necessarily reverse order it would be random when I get it – edmamerto Dec 13 '20 at 00:36
  • This is a *list of dictionaries*. In this case, `sorted(images["auto-init-container/auto-init-container"], key=lambda d: d['creation_date'], reverse=True)` – juanpa.arrivillaga Dec 13 '20 at 00:36

0 Answers0