给定一个带有计数元组列表的输入数组,例如
r, s = 0.5, 2.0 # floats, given, guaranteed nonzero, guaranteed nonequal
[
((+r, -r), 2),
((+s, -s), 1),
((0,), 2),
# ...
]
我想构建一个所有组合的列表,其中包含两个(+r, -r)
(可能都是+r
)、一个(+s, -s)
和两个0
,即
(+r, 0, -s, +r, 0),
(0, 0, -r, +r, +s),
...
可以有任意数量的元组。顺序不重要
有没有办法通过itertools实现这一点
我希望我正确理解了你的问题:
印刷品:
相关问题 更多 >
编程相关推荐