Skip to content Skip to sidebar Skip to footer

Sort List Of Dictionaries Based On Keys Inside The List

How can I sort this based on the key in dictionary? df1 = [('f', {'abe': 1}), ('f', {'tbeli': 1}), ('f', {'mos': 1}), ('f', {'esc': 1})] I tried this L1 = [year for (title, year)

Solution 1:

If all the dicts are going to be only 1 key/pair long then this should work.

L1=sorted(df1, key=lambda t: list(t[1].keys())[0])


Post a Comment for "Sort List Of Dictionaries Based On Keys Inside The List"