列表各种去重方法
1.列表嵌套字典去重
1-1. reduce方法
代码示例:
def list_dit_removal(lists):
""" 列表嵌套字典去重 """
removal_fun = lambda x,y: x if y in x else x + [y]
return reduce(removal_fun, [[], ] + lists)
"""
lists = [{'a':123},{'a':'123'}]
结果:
[{'a':123}]
"""
1-2. 方法二
代码示例:
def deleteDuplicate(li):
temp_list = list(set([str(i) for i in li]))
li=[eval(i) for i in temp_list]
return li
"""
lists = [{'a':123},{'a':'123'}]
结果:
[{'a':123}]
"""