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

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第三方库


热门话题
java Springboot数据JPA findByDate()   java是否可以有多个顶级树节点?   javahibernatehql。子查询中的多个   使用Twilio验证java Keyclope电话号码   java重写对象的toString()表示返回意外的符号   java Android最多每15分钟调用一个方法,否则使用保存的数据   在java swing中突出显示jeditorpane中的一些单词   java将时间戳转换为UTC时区   由于main中存在ArrayIndexOutOfBoundsException,导致java编译错误   java如何通过requestscope获取对象内部对象的值?   java访问安卓代码内的网站并检索生成的图像   java这种日期格式的模式是什么?   java解析包含超链接的xml字符串