Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. # This is a really old post, in the comments (and stackoverflow too) you'll find better solutions.
  2.  
  3. def find(key, dictionary):
  4. for k, v in dictionary.iteritems():
  5. if k == key:
  6. yield v
  7. elif isinstance(v, dict):
  8. for result in find(key, v):
  9. yield result
  10. elif isinstance(v, list):
  11. for d in v:
  12. for result in find(key, d):
  13. yield result
  14.  
  15. example = {'app_url': '', 'models': [{'perms': {'add': True, 'change': True, 'delete': True}, 'add_url': '/admin/cms/news/add/', 'admin_url': '/admin/cms/news/', 'name': ''}], 'has_module_perms': True, 'name': u'CMS'}
  16.  
  17. list(find('admin_url', example))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement