Python returns the list results of the database for sorting, comparable to order by id desc

Look at the code first, at a glance

params = [
    {'departcode': '230000000000', 'departname': 'XXXXX1', 'parentdepartcode': '2300'},
    {'departcode': '230100000000', 'departname': 'XXXXX2', 'parentdepartcode': '2300'},
    {'departcode': '230900000000', 'departname': 'XXXXX3', 'parentdepartcode': '2300'},
    {'departcode': '230910000000', 'departname': 'XXXXX0', 'parentdepartcode': '2300'}
]

print(params)
params1 = sorted(params,key=lambda x:x["departcode"],reverse=True)
print(params1)

Sort by the departcode field

Guess you like

Origin blog.csdn.net/lystest/article/details/131129005