将嵌套字典键转换为带点字符串及其相应值的基本字典

dict-dot-notate的Python项目详细描述


Build StatusCoverage Status

口述

dict_dot_notate将嵌套的字典键及其相应值转换为带点字符串的基本字典。在

安装

pip install dict-dot-notate

使用

^{pr2}$

示例

data = {
"obj": "obj",
"nested_once": {"first": "first"},
"nested_twice": {
    "twice": {"inner_nest": {"second": "second"}}
},
"nested_thrice": {
    "thrice": {"second_nest": {"tripple_nest": {"tripple": "thrice"}, "three": "three"}}
}
}

调用相关方法来转换dict

    result = dict_dot_notate(data)

输出

  {
    'obj': 'obj',
    'nested_once.first': 'first',
    'nested_twice.twice.inner_nest.second': 'second',
    'nested_thrice.thrice.second_nest.tripple_nest.tripple': 'thrice', 
    'nested_thrice.thrice.second_nest.three': 'three'
    }

如果传入的dict有列表值,则输出如下

示例

data = {
"obj": "obj",
"nested_once": {"first": "first"},
"nested_twice": {
    "twice": {"inner_nest": [1, 2, 3, 4, 5]}
}
}

转换

result = dict_dot_notate(data)

输出

{
'obj': 'obj',
'nested_once.first': 'first',
'nested_twice.twice.inner_nest': [1, 2, 3, 4, 5]
}

不传入词典列表。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
在Grails中集成javaapplet   动态设置片段时发生java错误   JavaSpringVelocity模板电子邮件?   SpringHateOAS中java自定义json输出   java wait()和notify()相关问题   正则表达式中的单词边界是什么?   使用外部库将项目部署到glassfish后发生java NoClassDefFoundError   java为什么在这里初始化ListNode两次?   java libGDX移动三维模型   java使线程等待另一个线程的执行   正则表达式如何在java中使用正则表达式解析给定字符串   java SWT ScrolledComposite在32768像素后切断画布生成的图像