0

I am getting a list like below:

[
    {
        'latitude': Decimal('0E-8'),
        'longitude': Decimal('0E-8'),
        'placeValue': None,
        'orgValue': {
            'step': u'dispatched',
            'time': u'2016-09-1 22: 15: 30.012000+00: 00'
        },
        'desiredValue': None
    },
    {
        'latitude': Decimal('0E-8'),
        'longitude': Decimal('0E-8'),
            'placeValue': {
            'time': u'2016-09-13 18: 15: 30.012000+00: 00',
            'step': u'on the way',
            'feedback':'satisfied'
           },
        'orgValue': None,
        'desiredValue': None
    }
]

I want to sort based on time. That means the dictionary which has latest time will placed as first & there on.

Saw some link of SO:link

As my data changes from 1 dictionary to another.So couldn't get a way to find the solution.Can some one share some idea?

Community
  • 1
  • 1
Sandy
  • 261
  • 1
  • 3
  • 13
  • You'll still need to write a key function; I've duped you to a question that has nested dictionaries; the key there sorts by the nested `'context'` value. You'll need to do the same; given a key-value pair, write a function that returns by what value exactly this should be sorted on. – Martijn Pieters Sep 13 '16 at 06:35
  • @Martijin- As my 3 dictionaries contains time which I am not sure when which dictionary will be null & when which dictianary will contain the time field.There I am winded up like how to proceed. – Sandy Sep 13 '16 at 06:41
  • Given **one** of the dictionaries, how would you get the time out? Start with that. – Martijn Pieters Sep 13 '16 at 06:45
  • @Martjin- I am able to sort those 3 dictionaries .But the problem starts when i adding other key in the main dictionary as like latitude,longitude in my Question – Sandy Sep 13 '16 at 07:11

0 Answers0