I'm doing some boring math with lot of sums over lot of variables. So, instead of nesting
for loops I have decided to use something like this:
def combo(*limits): if len(limits) == 1: for l in range(limits): yield [l] else: for l in range(limits): for l2 in combo(*limits[1:]): yield [l] + l2 if __name__=="__main__": for i, j, k in combo(2, 4, 5): print i, j, k
Do you like it? Could it be redone or should it be replaced by something else?