我希望按照“低级别”的值对字典进行排序。例如,如果我有结构:
salary_data = {"John D": {"wage":10000, "gender":male}, "Peter A":{"wage":12000, "gender":male}, "Emma":{"wage":5000, "gender":female}}
然后我希望在第二阶段(即["Emma", "John D", "Peter A"]
)返回按工资排序的初始字典的键。
答案 0 :(得分:3)
尝试这样的事情:
print sorted(salary_data, key=lambda k:salary_data[k]['wage'])
输出:
[' Emma',' John D',' Peter A']