我有下表:
table = [['5p,aa', '3p,ggg'], ['pippo,3', 'gigio,777']]
我想为每一行生成每一行的所有组合,如下所示:
5p,3p 5p,ggg aa,3p aa,ggg pippo,gigio pippo,777 3,gigio 3,777
你有什么建议?
答案 0 :(得分:0)
>>> import itertools
>>> table = [['5p,aa', '3p,ggg'], ['pippo,3', 'gigio,777']]
>>> rows = [[cell.split(',') for cell in row] for row in table]
>>> [list(itertools.product(*row)) for row in rows]
[[('5p', '3p'), ('5p', 'ggg'), ('aa', '3p'), ('aa', 'ggg')],
[('pippo', 'gigio'), ('pippo', '777'), ('3', 'gigio'), ('3', '777')]]