Last active
March 9, 2023 02:23
-
-
Save sakku116/11dd8dab9da09ecd502a6c6ee7b8e381 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generatePathsFromDictBasedPaths(d: dict, **kwargs): | |
""" | |
the point is just adding prefix to each key, | |
then call self function to proccess nested dict. | |
example: | |
``` | |
{ | |
"dashboard": {}, | |
"help": {}, | |
"others": { | |
"blog": {} | |
} | |
} | |
``` | |
return <generator>. | |
just convert `list(<generator>)` | |
result example: | |
``` | |
['/dashboard', | |
'/helo', | |
'/others', | |
'/others/blog'] | |
``` | |
""" | |
prefix = kwargs.get("prefix", "") | |
for key, value in d.items(): | |
if not prefix: | |
result = f"/{key}" | |
else: | |
result = f"{prefix}/{key}" | |
yield result | |
if len(value) != 0: | |
yield from generatePathsFromDictBasedPaths(value, prefix=result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment