import itertools
import os
dirs = [["Weights", "No_Weights"],
["Male", "Female"],
["Caucasian", "African-American", "Asian", "Hispanic", "Indo", "Other", "Unknown"],
["B20", "20", "30", "40", "50", "60", "70"]]
for item in itertools.product(*dirs):
os.makedirs(os.path.join(*item))
itertools.product()builds all possible variations of the path, then os.path.join()merges the subfolders together using the correct syntax for your platform.
EDIT: os.makedirs()required instead os.mkdir(). Only the first will build all the intermediate subdirectories in the full path.
source
share