running black on files and updating docs.

modified:   README.rst
	modified:   nested_lookup/nested_lookup.py
	modified:   test_nested_loopkup.py
This commit is contained in:
russellballestrini 2018-09-25 17:16:04 -04:00
parent 7260463455
commit 0d17bb8c7f
3 changed files with 84 additions and 99 deletions

View file

@ -2,6 +2,7 @@ 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:
@ -11,6 +12,7 @@ def nested_lookup(key, document, wild=False, with_keys=False):
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):
@ -30,7 +32,9 @@ def _nested_lookup(key, document, wild=False, with_keys=False):
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