n-dim permutation matrix/generator?

guenter.jantzen at prodv.de guenter.jantzen at prodv.de
Mon Nov 20 12:13:11 EST 2006


If your products are not too big you may use the following approach

def cross(*L):
    P=[()]
    for i in range(len(L)):
        P_=[]
        for p in P:
            for el in L[i]:
                P_.append(p+(el,))
        P = P_
    return P

if __name__ == '__main__':
    for x in cross((0,1,2), (0,1), (0,1)):
        print x




More information about the Python-list mailing list