Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a39f2af

Browse files
committed
Mention inefficiency of lists as queues, add link to collections.deque discussion.
1 parent 0b56ce0 commit a39f2af

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

Doc/tutorial/datastructures.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ the queue, use :meth:`pop` with ``0`` as the index. For example::
154154
>>> queue
155155
['Michael', 'Terry', 'Graham']
156156

157+
However, since lists are implemented as an array of elements, they are not the
158+
optimal data structure to use as a queue (the ``pop(0)`` needs to move all
159+
following elements). See :ref:`tut-list-tools` for a look at
160+
:class:`collections.deque`, which is designed to work efficiently as a queue.
161+
157162

158163
.. _tut-functional:
159164

0 commit comments

Comments
 (0)