fork(1) download
  1. def paths(some_dict, path=()):
  2. for key, value in some_dict.items():
  3. key_path = path + (key,)
  4. yield key_path
  5. if hasattr(value, 'items'):
  6. yield from paths(value, key_path)
  7.  
  8. d = {'a': {'b': {'c': {},'d': {'e': {}}}}}
  9. print(*paths(d), sep='\n')
  10.  
Success #stdin #stdout 0.01s 28384KB
stdin
Standard input is empty
stdout
('a',)
('a', 'b')
('a', 'b', 'd')
('a', 'b', 'd', 'e')
('a', 'b', 'c')