How to remove these duplicates in a list (python)

前端 未结 5 2033
野的像风
野的像风 2021-01-03 15:26
biglist = 

[ 

    {\'title\':\'U2 Band\',\'link\':\'u2.com\'}, 
    {\'title\':\'ABC Station\',\'link\':\'abc.com\'}, 
    {\'title\':\'Live Concert by U2\',\'link         


        
5条回答
  •  孤城傲影
    2021-01-03 16:03

    You can use defaultdict to group items by link, then removed duplicates if you want to.

    from collections import defaultdict
    
    nodupes = defaultdict(list)
    for d in biglist:
        nodupes[d['url']].append(d['title']
    

    This will give you:

    defaultdict(, {'abc.com': ['ABC Station'], 'u2.com': ['U2 Band', 
    'Live Concert by U2']})
    

提交回复
热议问题