python3 两层dict字典转置

博客介绍了Python 3中两层字典的反向转置操作。给出了两层字典的结构,如dict =(type, dict2),dict2 = (k_value, index) ,并将其反向转置为dict = (index, type) 。

python3;

 

 两层字典

dict =(type, dict2) 

dict2 = (k_value, index)

dictss = {
        10: {3: 1,  4: 2,  5:  3, 6: 4,  7: 5,  8: 6,   9: 7,   10: 8,  11: 9,  12: 10, 13: 11, 14: 12, 15: 13, 16: 14, 17: 15, },
        20: {3: 16, 4: 17, 5: 18, 6: 19, 7: 20, 8: 21,     9: 22,     10: 23, 11: 24,    12: 25,    13: 26, 14: 27,    15: 28, },
}

反向转置字典,

dict = (index, type)

rev_dictss = {}
for (k, v) in dictss.items():
    # print(dict(v))
    for vk, vv in v.items():
        # print(vv, vk)
        rev_dictss[vv] = k

print(rev_dictss)

 

转载于:https://www.cnblogs.com/xiaoniu-666/p/10553812.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值