标签:demo sort rgb lam style ems int ict sorted
例:
根据value值排序
hasd = { ‘a‘: 12, ‘c‘: 7, ‘d‘: 17, ‘m‘: -9 } demo_dict = sorted(hasd.items(),key=lambda x:x[1]) print(demo_dict)
[(‘m‘, -9), (‘c‘, 7), (‘a‘, 12), (‘d‘, 17)]
根据key排序
hasd = { ‘a‘: 12, ‘c‘: 7, ‘d‘: 17, ‘m‘: -9 } s = sorted(hasd.items(),key=lambda x:x[0]) print(demo_dict)
[(‘a‘, 12), (‘c‘, 7), (‘d‘, 17), (‘m‘, -9)]
标签:demo sort rgb lam style ems int ict sorted
原文地址:https://www.cnblogs.com/momo521/p/14767878.html