擅长:python、mysql、java
<p>您可以使用<code>itertools.combinations</code>(这将提供重复项)和<code>set</code>来过滤重复项:</p>
<pre><code>from itertools import combinations
from functools import reduce
from operator import mul
factors = [2, 2, 3, 5, 5]
set(reduce(mul, combination) for i in range (1, len(factors) + 1) for combination in combinations(factors, i))
</code></pre>
<p>输出:</p>
<pre><code>{2, 3, 4, 5, 6, 10, 12, 15, 20, 25, 30, 50, 60, 75, 100, 150, 300}
</code></pre>