Selects the line you want something like ...:
if all(d in path.split('/') for d in dirs):
...
This one-line style is inefficient, as it maintains a splitting path for each d (and split makes a list, while a set is better for membership verification). Introducing it in 2-layer:
pathpieces = set(path.split('/'))
if all(d in pathpieces for d in dirs):
...
significantly improves performance.
source
share