如果我有: a=[[1,2,3],['a','b'],[7,8,9],['c','d','e']]
我知道我应该使用: for t in itertools.product(*a):
print t
让所有组合,如 [(1,'a',7,'c'),(1,'a',7,'d')....]
但是,如果我想设置元素的长度子序列,我该怎么做? 例如,结果我想是(如果我设置3作为长度):
下在Python 3.6从不打印任何东西 from itertools import product, count
for f in product(count(), [1,2]):
print(f)
相反,它只是坐在那里和烧伤CPU。这个问题似乎是,product永远不会返回迭代器,因为它首先评估整个product。这是令人惊讶的,因为product应该是一个发电机。 我本来期
我有一个数据帧,看起来像: IDs
Name
John 1,4,8
Eric 2,9,17
Paul 41,72,78,100
我需要从IDs每一个组合,并将其分配给新的原料,所以输出DF应看起来像这样: IDs
Name
John 1,4
John 1,8
John 4,8
Eric 2,9
Eric 2,17
Eric 9,17