Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
4-liner: compact recursive solution in Creative category for The Flat Dictionary by przemyslaw.daniel
def flatten(d, p=''):
if not isinstance(d, dict) or not d: return [(p, d or '')]
r = sum([flatten(v, p+'/'*bool(p)+k) for k, v in d.items()], [])
return r if p else dict(r)
March 21, 2018