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