I have a list which I have gotten from json.loads();
myList = [{'label': 'Users', 'host': 'XYZ', 'tags': {'customer': 'XYZ'}, 'data': [[1518756360, 1]]},
{'label': 'Users', 'host': 'ABC', 'tags': {'customer': 'ABC'}, 'data': [[1518756360, 1]]},
{'label': 'Users', 'host': 'EFG', 'tags': {'customer': 'EFG'}, 'data': [[1518756360, 1]]}]
Is there a way to sort this list based of host
key so that it becomes like this?
mySortedList = [{'label': 'Users', 'host': 'ABC', 'tags': {'customer': 'ABC'}, 'data': [[1518756360, 1]]},
{'label': 'Users', 'host': 'EFG', 'tags': {'customer': 'EFG'}, 'data': [[1518756360, 1]]},
{'label': 'Users', 'host': 'XYZ', 'tags': {'customer': 'XYZ'}, 'data': [[1518756360, 1]]}]
I tried myList.sort()
and myList.sort(key='host')
but it didn't work.