1. 字典列表,按字典某个键值去重
def list_dict_set(dict_list, key_name):
b = OrderedDict()
for item in dict_list:
b.setdefault(item[key_name], {**item, })
b = list(b.values())
return b
2. 字典列表,按字典某个键值排序
def list_dict_sort(dict_list, key_name):
return sorted(dict_list, key=lambda dic: dic[key_name], reverse=True)
网友评论