回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>关于这个问题有很多问题,但就我而言,这些问题是行不通的。我正在尝试查找给定目标键和值对的嵌套字典。我的递归函数返回none(修复后,max depth recursive error)。你知道吗</p>
<pre><code>def recursive_lookup(k, sv, d):
if k in d: return d[k]
for v in d.values():
if isinstance(v, dict):
a = recursive_lookup(k, sv, v)
if a == sv:
if a is not None:
return d
return None
def run():
maly = {'_id': "ObjectId('5def7e8c4802b906dd067f97')", 'METADATA': {'Tags': {'AcquisitionTime': '2019-02-05T15:59:37.5862118Z', 'ImageScaling': {'ImageScaling': {'ImagePixelSize': '4.54,4.54'}}, 'DetectorState': {'CameraState': {'ApplyCameraProfile': 'false', 'ApplyImageOrientation': 'true', 'ExposureTime': '2200000', 'Frame': '0,0,2752,2208', 'ImageOrientation': '3'}}, 'StageXPosition': '+000000141526.5820', 'StageYPosition': '+000000189329.5000', 'FocusPosition': '+000000002097.2550', 'RoiCenterOffsetX': '+000000000000.0000', 'RoiCenterOffsetY': '+000000000000.0000'}, 'DataSchema': None, 'AttachmentSchema': None}}
returned_value = recursive_lookup("FocusPosition", "+000000002097.2550", maly)
print(returned_value)
run()
</code></pre>
<p>如果我把<code>return d</code>改成<code>recursive_lookup(k, sv, d)</code>,它也不起作用。
它本应归还苹果词典,但却一本也没有归还。你知道吗</p>
<p>我怎样才能解决那个问题?你知道吗</p>