<p>@暗影护林员说得对,你应该告诉我们更多关于你想做什么的细节好的。这些我的建议。</p>
<ul>
<li><p>首先,检查代码,找出问题的瓶颈,而不是仅仅猜猜。如果您想做的不是I/O绑定,也许多处理是一个好选择。</p></li>
<li><p>数据结构非常重要因素。如果您想处理大型对象,最好的方法是选择最合适的数据结构。也许您可以尝试<a href="https://docs.python.org/2/library/collections.html#collections.deque" rel="nofollow noreferrer">deque</a>这是一个列表式容器,具有快速附件,两端都会弹出,而不是^{{cd1>}。</p></li>
</ul>
<blockquote>
<p>Deques are a generalization of stacks and queues (the name is
pronounced “deck” and is short for “double-ended queue”). Deques
support thread-safe, memory efficient appends and pops from either
side of the deque with approximately the same O(1) performance in
either direction.</p>
</blockquote>
<ul>
<li><p>内存管理,如果数据的大小非常大,请尝试围绕^{{cd2>}和^{cd3>}构造此代码,而不是大量的项目列表,它将帮助您避免内存耗尽,并改进代码。</p></li>
<li><p><a href="https://docs.python.org/2/library/mmap.html" rel="nofollow noreferrer">mmap</a>可能会帮助您处理大型文件。</p></li>
</ul>
<blockquote>
<p>Memory-mapped file objects behave like both strings and like file
objects.</p>
</blockquote>
<p>请参阅<a href="https://docs.python.org/2/library/collections.html#collections.deque" rel="nofollow noreferrer">High-performance container datatypes</a>中的详细信息。</p>