Skip to content

Instantly share code, notes, and snippets.

View homata123's full-sized avatar

Hồ Mạnh Thắng homata123

View GitHub Profile
@SegFaultAX
SegFaultAX / traverse.py
Created February 3, 2017 21:34
Traverse a Python dict and find all key paths
def iter_paths(d):
def iter1(d, path):
paths = []
for k, v in d.items():
if isinstance(v, dict):
paths += iter1(v, path + [k])
paths.append((path + [k], v))
return paths
return iter1(d, [])