parent
4402da08fe
commit
3441584eaa
3 changed files with 51 additions and 38 deletions
|
|
@ -49,17 +49,18 @@ def get_all_keys(dictionary):
|
|||
result_list = []
|
||||
|
||||
def recrusion(dictionary):
|
||||
if hasattr(dictionary, 'items'):
|
||||
for key, value in iteritems(dictionary):
|
||||
if isinstance(value, dict):
|
||||
result_list.append(key)
|
||||
recrusion(dictionary=value)
|
||||
elif isinstance(value, list):
|
||||
result_list.append(key)
|
||||
for list_items in value:
|
||||
for key, value in iteritems(dictionary):
|
||||
if isinstance(value, dict):
|
||||
result_list.append(key)
|
||||
recrusion(dictionary=value)
|
||||
elif isinstance(value, list):
|
||||
result_list.append(key)
|
||||
for list_items in value:
|
||||
# Make sure the items inside the list is iterable
|
||||
if hasattr(list_items, 'items'):
|
||||
recrusion(dictionary=list_items)
|
||||
else:
|
||||
result_list.append(key)
|
||||
else:
|
||||
result_list.append(key)
|
||||
|
||||
recrusion(dictionary=dictionary)
|
||||
return result_list
|
||||
|
|
@ -105,17 +106,19 @@ def _get_occurrence(dictionary, item, keyword):
|
|||
occurrence = [0]
|
||||
|
||||
def recrusion(dictionary):
|
||||
if hasattr(dictionary, 'items'):
|
||||
if item == 'key':
|
||||
occurrence[0] += 1 if dictionary.get(keyword) else 0
|
||||
elif keyword in dictionary.values():
|
||||
occurrence[0] += dictionary.values().count(keyword)
|
||||
for key, value in iteritems(dictionary):
|
||||
if isinstance(value, dict):
|
||||
recrusion(dictionary=value)
|
||||
elif isinstance(value, list):
|
||||
for list_items in value:
|
||||
if item == 'key':
|
||||
occurrence[0] += 1 if dictionary.get(keyword) else 0
|
||||
elif keyword in dictionary.values():
|
||||
occurrence[0] += dictionary.values().count(keyword)
|
||||
for key, value in iteritems(dictionary):
|
||||
if isinstance(value, dict):
|
||||
recrusion(dictionary=value)
|
||||
elif isinstance(value, list):
|
||||
for list_items in value:
|
||||
if hasattr(list_items, 'items'):
|
||||
recrusion(dictionary=list_items)
|
||||
elif list_items == keyword:
|
||||
occurrence[0] += 1 if item == 'value' else 0
|
||||
|
||||
recrusion(dictionary=dictionary)
|
||||
return occurrence[0]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue