The internet 2021-06-19 14:33 采纳率: 25%
浏览 64
已采纳

我现在有一个类似于这样的字典套列表 怎样把他们合并成一个 相同key下值的value合并并去重

[{'config': [], 'video': ['create', 'list', 'AIreview', 'download', 'approve', 'modify', 'read'], 'channel': ['create', 'modify', 'read', 'list', 'delete', 'approve'], 'webpage': ['list'], 'organization': ['subsidiaries_list', 'channel_list', 'video_list'], 'account': ['list', 'modify_self', 'read_self'], 'catalog': []}

{'config': [], 'video': ['create', 'list', 'modify', 'read', 'delete', 'AIreview', 'download'], 'channel': ['create', 'modify', 'read', 'list', 'delete', 'approve'], 'webpage': ['list'], 'organization': ['subsidiaries_list', 'channel_list', 'video_list'], 'account': ['list', 'modify_self', 'read_self'], 'catalog': []}]


 

  • 写回答

1条回答 默认 最新

  • Roc-xb 后端领域优质创作者 2021-06-19 15:18
    关注
    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    """
    @author: YangPC
    @time:2021/06/18
    @QQ:327844761
    @微信公众号:ewbang
    """
    
    if __name__ == '__main__':
        d = [{'config': [], 'video': ['create', 'list', 'AIreview', 'download', 'approve', 'modify', 'read'],
              'channel': ['create', 'modify', 'read', 'list', 'delete', 'approve'], 'webpage': ['list'],
              'organization': ['subsidiaries_list', 'channel_list', 'video_list'],
              'account': ['list', 'modify_self', 'read_self'], 'catalog': []},
             {'config': [], 'video': ['create', 'list', 'modify', 'read', 'delete', 'AIreview', 'download'],
              'channel': ['create', 'modify', 'read', 'list', 'delete', 'approve'], 'webpage': ['list'],
              'organization': ['subsidiaries_list', 'channel_list', 'video_list'],
              'account': ['list', 'modify_self', 'read_self'], 'catalog': []}]
    
        new_d = {};
        for item in d:
            for key in item.keys():
                if key not in new_d:
                    new_d[key] = item[key]
                else:
                    new_d[key] = list(set(new_d[key] + item[key]))
    
        print(new_d)
    

    若有帮助,望采纳!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档