From: Georg Brandl Date: Sun, 21 Mar 2010 09:37:54 +0000 (+0000) Subject: Mention inefficiency of lists as queues, add link to collections.deque discussion. X-Git-Tag: v2.7b1~291 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a39f2afe9be7511bdb0d064dc5b14cf1ae4aa401;p=python Mention inefficiency of lists as queues, add link to collections.deque discussion. --- diff --git a/Doc/tutorial/datastructures.rst b/Doc/tutorial/datastructures.rst index a56fd2b042..669dfc465f 100644 --- a/Doc/tutorial/datastructures.rst +++ b/Doc/tutorial/datastructures.rst @@ -154,6 +154,11 @@ the queue, use :meth:`pop` with ``0`` as the index. For example:: >>> queue ['Michael', 'Terry', 'Graham'] +However, since lists are implemented as an array of elements, they are not the +optimal data structure to use as a queue (the ``pop(0)`` needs to move all +following elements). See :ref:`tut-list-tools` for a look at +:class:`collections.deque`, which is designed to work efficiently as a queue. + .. _tut-functional: