python3 两层dict字典转置

Posted 只言片语

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python3 两层dict字典转置相关的知识,希望对你有一定的参考价值。

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字典转置的主要内容,如果未能解决你的问题,请参考以下文章

Python3-笔记-B-002-数据结构-字典dict{ }

python3 字典dict

Python3基础 dict 创建字典 空字典

Python3学习笔记-字典(dict)

Python3基础 dict 创建字典 空字典

Python代码阅读(第19篇):合并多个字典