欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python中list中的元素为字典,对字典中value相同的进行分组

程序员文章站 2022-05-21 16:17:30
...
hosts_nodes为一个list中的元素为字典
def match_rac_disks(hosts_nodes):
    result = list()
    select_checked = list()
    for j in hosts_nodes:
        for k in j['branch']:
            if 'checked' in k:
                k['map_disk_lab'] = j['label']
                k['host_ident'] = j['id']
                select_checked.append(k)
    for i in range(len(select_checked)):
        if len(select_checked) != 0:
            tmp = list()
            tmp2 = list()
            tmp.append(select_checked[0])
            tmp2.append(0)
            for j in range(1, len(select_checked)):
                if select_checked[0]['id'] == select_checked[j]['id']:
                    tmp.append(select_checked[j])
                    tmp2.append(j)
            result.append(tmp)
            for index, s in enumerate(tmp2):
                del select_checked[s - index]
        else:
            break
    return result