есть двумерный массив
[[1][a] [2][b] [3][c] [4][d]]
[1,2,3,4], [1,2,3,d], [1,2,c,4], [1,2,c,d], [1,b,3,4], [1,b,3,d], [1,b,c,4], [1,b,c,d], ...
[[1][a] [2][b] [3][c] [4][d]]
[1,2,3,4], [1,2,3,d], [1,2,c,4], [1,2,c,d], [1,b,3,4], [1,b,3,d], [1,b,c,4], [1,b,c,d], ...
theproshinПо какому принципу строится второй список?
Необходимо получитьт список типа:
a = [1,'a', 2,'b', 3,'c', 4,'d'] b = [] for i in xrange(16): b.append([]) for i, j in enumerate("%04d"%int(bin(x)[2:])) + bin(i)[2:]): b[-1].append(a[i*2+int(j)]) print b
a = [1,'a', 2,'b', 3,'c', 4,'d'] b = [[a[int(i*2+int(j))] for i, j in enumerate('0'*(4-len(bin(x)[2:])) + bin(x)[2:])] for x in xrange(16)] print b
data = [['1', 'a'], ['2', 'b'], ['3', 'c'], ['4', 'd']] def mkmask(n, w): return map(int, bin(n)[2:].zfill(w)) def domagic(data): w = len(data) for c in range(1 << w): m = mkmask(c, w) yield [p[m[i]] for i, p in enumerate(data)] print(list(domagic(data)))