Python: How to sort a list by given value in inner dictionary? -


i have list, looks this:

c = [       [129211, [{'cid': 142211, 'date': 1478550075, 'likes': {'count': 40}]       [128732, [{'cid': 142061, 'date': 1478550100, 'likes': {'count': 17}]       ...     ] 

how copy of list sorted values of 'count' in 'likes' (in case it's 40 , 17)?

simply use appropriate sort key.

c = [       [129211, [{'cid': 142211, 'date': 1478550075, 'likes': {'count': 40}}]],       [128732, [{'cid': 142061, 'date': 1478550100, 'likes': {'count': 17}}]]     ] s = sorted(c, key=lambda i: i[1][0]['likes']['count']) 

note current list c not structured - i've repaired incorrect syntax.

result:

>>> import pprint >>> pprint.pprint(s) [[128732, [{'cid': 142061, 'date': 1478550100, 'likes': {'count': 17}}]],  [129211, [{'cid': 142211, 'date': 1478550075, 'likes': {'count': 40}}]]] 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -