擅长:python、mysql、java
<p><a href="http://docs.python.org/library/itertools.html#itertools.permutations" rel="noreferrer">^{<cd1>}</a>可以帮你。</p>
<pre><code>>>> l = ['hel', 'lo', 'bye']
>>> list(itertools.permutations(l, 2))
[('hel', 'lo'), ('hel', 'bye'), ('lo', 'hel'), ('lo', 'bye'), ('bye', 'hel'), ('bye', 'lo')]
</code></pre>
<p>或者如果需要组合,可以使用<a href="http://docs.python.org/library/itertools.html#itertools.combinations" rel="noreferrer">^{<cd2>}</a>。</p>
<pre><code>>>> l = ['hel', 'lo', 'bye']
>>> list(itertools.combinations(l, 2))
[('hel', 'lo'), ('hel', 'bye'), ('lo', 'bye')]
</code></pre>