擅长:python、mysql、java
<p>要获得340个元素的相同结果,可以使用<a href="https://docs.python.org/3/library/itertools.html#itertools.product" rel="nofollow noreferrer">^{<cd1>}</a>:</p>
<pre><code>product(n, repeat=1)
product(n, repeat=2)
...
product(n, repeat=4)
</code></pre>
<p>要打印结果,可以使用以下循环:</p>
<pre><code>from itertools import product
n = "abcd"
for i in range(1, 5):
for prod in product(n, repeat=i):
print(''.join(prod))
</code></pre>
<p>为了获得额外的等级,你可以很容易地增加<a href="https://docs.python.org/3/library/functions.html#func-range" rel="nofollow noreferrer">^{<cd2>}</a>中的5。注意:打印顺序与代码中的略有不同。你知道吗</p>