Reverted PEP8 correction
This commit is contained in:
parent
bb7ab509eb
commit
c1ca4c1e1e
2 changed files with 26 additions and 39 deletions
|
|
@ -2,26 +2,20 @@ from six import iteritems
|
|||
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
def nested_lookup(key, document, wild=False, with_keys=False):
|
||||
"""Lookup a key in a nested document, return a list of values"""
|
||||
if with_keys:
|
||||
d = defaultdict(list)
|
||||
for k, v in _nested_lookup(
|
||||
key, document, wild=wild, with_keys=with_keys
|
||||
):
|
||||
for k, v in _nested_lookup(key, document, wild=wild, with_keys=with_keys):
|
||||
d[k].append(v)
|
||||
return d
|
||||
return list(_nested_lookup(key, document, wild=wild, with_keys=with_keys))
|
||||
|
||||
|
||||
def _nested_lookup(key, document, wild=False, with_keys=False):
|
||||
"""Lookup a key in a nested document, yield a value"""
|
||||
if isinstance(document, list):
|
||||
for d in document:
|
||||
for result in _nested_lookup(
|
||||
key, d, wild=wild, with_keys=with_keys
|
||||
):
|
||||
for result in _nested_lookup(key, d, wild=wild, with_keys=with_keys):
|
||||
yield result
|
||||
|
||||
if isinstance(document, dict):
|
||||
|
|
@ -32,15 +26,11 @@ def _nested_lookup(key, document, wild=False, with_keys=False):
|
|||
else:
|
||||
yield v
|
||||
elif isinstance(v, dict):
|
||||
for result in _nested_lookup(
|
||||
key, v, wild=wild, with_keys=with_keys
|
||||
):
|
||||
for result in _nested_lookup(key, v, wild=wild, with_keys=with_keys):
|
||||
yield result
|
||||
elif isinstance(v, list):
|
||||
for d in v:
|
||||
for result in _nested_lookup(
|
||||
key, d, wild=wild, with_keys=with_keys
|
||||
):
|
||||
for result in _nested_lookup(key, d, wild=wild, with_keys=with_keys):
|
||||
yield result
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue