Updated README.rst and set list as default output
This commit is contained in:
parent
dfc2483e3e
commit
3b1f2ced67
2 changed files with 67 additions and 33 deletions
|
|
@ -1,15 +1,13 @@
|
|||
from six import iteritems
|
||||
|
||||
def nested_lookup(key, document, wild=False, output='dict'):
|
||||
def nested_lookup(key, document, wild=False, output='list'):
|
||||
"""Lookup a key in a nested document, return a list of values"""
|
||||
if output == 'dict':
|
||||
return dict(_nested_lookup(key, document, wild=wild, output=output))
|
||||
elif output == 'list':
|
||||
return list(_nested_lookup(key, document, wild=wild, output=output))
|
||||
else:
|
||||
raise ValueError('Output is of unknown type '+output)
|
||||
return list(_nested_lookup(key, document, wild=wild, output=output))
|
||||
|
||||
def _nested_lookup(key, document, wild=False, output='dict'):
|
||||
def _nested_lookup(key, document, wild=False, output='list'):
|
||||
"""Lookup a key in a nested document, yield a value"""
|
||||
if isinstance(document, list):
|
||||
for d in document:
|
||||
|
|
@ -21,7 +19,7 @@ def _nested_lookup(key, document, wild=False, output='dict'):
|
|||
if key == k or (wild and key.lower() in k.lower()):
|
||||
if output == 'dict':
|
||||
yield k, v
|
||||
elif output == 'list':
|
||||
else:
|
||||
yield v
|
||||
elif isinstance(v, dict):
|
||||
for result in _nested_lookup(key, v, wild=wild, output=output):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue