Python Sort Object List by Attribute

August 20, 2018

Sort items by posted_date attribute in reverse order.

items = ...
items.sort(key=lambda x: x.posted_date, reverse=True)

for _item in items:
    print(_item.posted_date)
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.