def _nested_update, counter "run" was cleared on recursion.
Created by: Medex81
def _nested_update, counter "run" was cleared on recursion.
WORKED
def _nested_update(
document, key, value, val_len, run=[0]
):
if isinstance(document, list):
for list_items in document:
_nested_update(document=list_items, key=key, value=value,
val_len=val_len, run=run)
elif isinstance(document, dict):
if document.get(key):
# check if a value with the coresponding index exists and
# use it otherwise recycle the intially given value
if run[0] < val_len:
val = value[run[0]]
else:
run[0] = 0
val = value[run[0]]
document[key] = val
run[0] = run[0] + 1
for dict_key, dict_value in iteritems(document):
_nested_update(document=dict_value, key=key, value=value,
val_len=val_len, run=run)
return document