How can I simplify these nested for loops?
问题 I would like to make this simplified so that I can control how many nested for loops there are. Essentially this would be 3 for d1 in ['left','right','up','down']: for d2 in CreateDirectionList(d1): for d3 in CreateDirectionList(d2): #Do something with list [d1, d2, d3] return False and 4 would be for d1 in ['left','right','up','down']: for d2 in CreateDirectionList(d1): for d3 in CreateDirectionList(d2): for d4 in CreateDirectionList(d3): #Do something with list [d1, d2, d3, d4] return False