擅长:python、mysql、java
<p>您可以转置元组并将其映射到列表,或者使用map和itemgetter。在</p>
<pre><code>from operator import itemgetter
l = [(4, 4), (4, 5), (4, 6), (4, 7), (4, 8), (3, 8), (2, 8), (1, 8), (1, 9)]
a,b = map(itemgetter(0),l), map(itemgetter(1),l)
print(a,b)
a,b = map(list,zip(*l))
print(a,b)
[4, 4, 4, 4, 4, 3, 2, 1, 1] [4, 5, 6, 7, 8, 8, 8, 8, 9]
[4, 4, 4, 4, 4, 3, 2, 1, 1] [4, 5, 6, 7, 8, 8, 8, 8, 9]
</code></pre>
<p>您需要在类中添加<code>iter</code>,以便可以迭代对象:</p>
^{pr2}$
<p>对于<code>bfs</code>,使用<a href="http://pymotw.com/2/Queue/" rel="nofollow">Queue</a>将是一个有效的解决方案:</p>