码迷,mamicode.com
首页 > 编程语言 > 详细

python3 两层dict字典转置

时间:2019-03-18 18:36:36      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:字典   反向   span   value   item   ems   cts   python3   index   

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)

 

python3 两层dict字典转置

标签:字典   反向   span   value   item   ems   cts   python3   index   

原文地址:https://www.cnblogs.com/xiaoniu-666/p/10553812.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!