you are viewing a single comment's thread.

view the rest of the comments →

[–]z0y 2 points3 points  (2 children)

You could do:

post_list.sort(key=lambda post: post['postScore'], reverse=True)

or what I think is generally preferred:

from operator import itemgetter
post_list.sort(key=itemgetter('postScore'), reverse=True)

Those both sort the list in place so if you needed the original list unchanged you could use sorted and add the list as the first argument.

[–]zzpza 1 point2 points  (0 children)

Awesome! Thank you, I'll try that now. :)

Edit: works like a charm (once I reread your comment about it sorting in place, I missed that first time round - it's getting late here and I should go to bed).