Created
July 6, 2019 08:50
-
-
Save acdimalev/667319d83ce10adf6e0d1724871dbc86 to your computer and use it in GitHub Desktop.
Fun with directory recursion and Python
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
fix = lambda f: lambda x: f(fix(f), x) | |
# presume Python's obsession with iterators... | |
join = __import__('itertools').chain.from_iterable | |
bind = lambda f, xs: join(map(f, xs)) | |
# I/O primitives... | |
(subpaths, subdirs) = (lambda os: ( | |
lambda path: [os.path.join(path, x) for x in os.listdir(path)], | |
lambda path: [x for x in subpaths(path) if os.path.isdir(x)], | |
))(__import__('os')) | |
# subdirs of subdirs... | |
step_subdirs = lambda f, dirs: dirs and dirs + f(list(bind(subdirs, dirs))) | |
recurse_subdirs = fix(step_subdirs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment