【发布时间】:2021-07-30 14:21:46
【问题描述】:
body = {
'a': 1,
'b': 'apple',
'child': [
{
'a': 12,
'b': 'banana',
'child': [
{
'a': 121,
'b': 'mango',
'child': [
{
'a': 1211,
'b': 'coconut',
'child': [dynamic nested]
}
]
},
{
'a': 122,
'b': 'papaya',
'child': [
{
'a': 1221,
'b': 'lemon',
'child': [dynamic nested]
}
]
}
]
},
{
'a': 13,
'b': 'orenge',
'child': [
dynamic nested
]
}
]
}
如果我想知道 'coconut' 或 'lemon' 的索引(json body dynamic children sub child 我不知道 dee child,但是 khow 'a' or 'b' for find index deep)
如何用python获取索引?
ex1: index of 'coconut' = [0,0,0]
ex2: index of 'lemon' = [0,1,0]
【问题讨论】:
-
你能分享一下你在代码方面尝试过什么来解决这个问题吗?
-
我使用此代码查找'a'或'b'但我不知道查找索引此项目link
-
请在描述中添加代码而不是提供链接
标签: python python-3.x