擅长:python、mysql、java
<p>没什么要做的,但由于有点太复杂,速度会受到影响。
您可以这样提高程序速度:</p>
<pre><code>def begin():
graph = {}
for line in open('/home/edd91/Documents/SCC.txt'):
# consider only first 2 fields: avoids the loop and the append: that's the best saver
# there must not be 2 spaces between the numbers (in your original program neither so not a problem)
tempArray = line.split()
v1 = tempArray[1] # copy to get rid of array
if v1 in graph: # no need to use .keys()
graph[v1]['g'].append(tempArray[0])
else:
graph[v1] = {'g': [tempArray[0],], 's': False, 't': None, 'u': None }
print len(graph)
</code></pre>
<p>你可以先用一个中等大小的文件来比较速度和你原来的程序。你知道吗</p>