擅长:python、mysql、java
<p>尝试执行:</p>
<pre><code>dct = dict()
dct['hits'] = dict()
dct['hits']['hits'] = dict()
dct['hits']['hits']['a'] = 'b'
dct['hits']['hits']['b'] = 'c'
dct['aggregations'] = dict()
dct['aggregations']['a'] = 1
dct['aggregations']['b'] = 2
def foo(dct, *fields):
n = len(fields)
for idx in range(n):
if idx == n - 1:
return dct[fields[idx]]
else:
dct = dct[fields[idx]]
print(foo(dct, 'hits'))
print(foo(dct, 'hits', 'hits'))
print(foo(dct, 'hits', 'hits', 'a'))
print(foo(dct, 'aggregations'))
print(foo(dct, 'aggregations', 'a'))
</code></pre>