擅长:python、mysql、java
<p>我猜你在找<a href="http://docs.python.org/2/library/itertools.html#itertools.product" rel="nofollow">^{<cd1>}</a>:</p>
<pre><code>>>> from itertools import product
>>> row1 = ['a', 'b', 'c', 'd']
>>> row2 = ['s', 'c', 'e', 'd', 'a']
>>> seen = set() #keep a track of already visited pairs in this set
>>> for x,y in product(row1, row2):
if (x,y) not in seen and (y,x) not in seen:
print x,y
seen.add((x,y))
seen.add((y,x))
...
a s
a c
a e
a d
a a
b s
b c
b e
b d
b a
c s
c c
c e
c d
d s
</code></pre>
<p><strong>更新:</strong></p>
^{pr2}$