Skip to content Skip to sidebar Skip to footer

Sort Json List From Another List

I'm trying to sort a json list from another list. example: jsonList = [{'id': 'das', 'name': 'something'}, {'id': 'rtn', 'name': 'Something Else'}, {'id': 'ddsn', 'name': 'Somethin

Solution 1:

goodList = sorted(jsonList, key=lambda x: orderList.index(x['id']))

or if you want just sort by id

sorted(jsonList, key=lambda x : x['id'])


Post a Comment for "Sort Json List From Another List"