data = [
{"Quantumtunneling_193d9d14381f11efbbeb000d3a096647": "Quantumtunneling_193d9d14381f11efbbeb000d3a096647.docx"},
{"Quantumtunneling_193d9d14381f11efbbeb000d3a096647": "Quantumtunneling_193d9d14381f11efbbeb000d3a096647.docx"},
{"Asymptoticfreedom_193cbc00381f11efbbeb000d3a096647": "Asymptoticfreedom_193cbc00381f11efbbeb000d3a096647.docx"},
{"Asymptoticfreedom_193cbc00381f11efbbeb000d3a096647": "Asymptoticfreedom_193cbc00381f11efbbeb000d3a096647.docx"}
]
我现在有个这个array key需要按照key去重,一开始用list(set())去重,但是发现set不能传入dict.
这样做就可以用某个key来去重
# 原始数据
data = [
{"Quantumtunneling_193d9d14381f11efbbeb000d3a096647": "Quantumtunneling_193d9d14381f11efbbeb000d3a096647.docx"},
{"Quantumtunneling_193d9d14381f11efbbeb000d3a096647": "Quantumtunneling_193d9d14381f11efbbeb000d3a096647.docx"},
{"Asymptoticfreedom_193cbc00381f11efbbeb000d3a096647": "Asymptoticfreedom_193cbc00381f11efbbeb000d3a096647.docx"},
{"Asymptoticfreedom_193cbc00381f11efbbeb000d3a096647": "Asymptoticfreedom_193cbc00381f11efbbeb000d3a096647.docx"}
]
# 将字典转换为元组进行去重
unique_tuples = list(set(tuple(d.items())[0] for d in data))
# 将元组转换回字典
unique_list = [{k: v} for k, v in unique_tuples]
# 打印结果
import json
print(json.dumps(unique_list, indent=2, ensure_ascii=False))