How to sort a list of dictionaries based on two different values? [duplicate]

Solution 1:

You can use .sort(), passing in a lambda function as the key parameter. The key is a tuple with tbl_nm as the first element, and seq as the second element. This means we sort on tbl_nm first, then use seq if two dictionaries have the same tbl_nm value.

data.sort(key=lambda x: (x["tbl_nm"], x["seq"]))
print(data)