Skip to content

Commit 811ef74

Browse files
Update 5.1.2. Using Lists as Queues in python tutorial
Apologies if the formatting for this pull request isn't correct. In the description for 5.1.2. Using Lists as Queues, within the Data Structures section of the tutorial, the fact that appending and popping to the left of lists is inefficient is mentioned, and that one should instead use the deque object which was designed to have fast appends and pops from both ends. But then in the example code we only have an example for how to remove elements from the left of the list and not add them. It's relatively straightforward that the method is appendleft(), but on first read I assumed that there was no implementation for this in the deque object as I didn't see it in the examples and it seemed to make intuitive sense that one shouldn't add elements to the start of queue.
1 parent fca5529 commit 811ef74

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

Doc/tutorial/datastructures.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ have fast appends and pops from both ends. For example::
188188
'John'
189189
>>> queue # Remaining queue in order of arrival
190190
deque(['Michael', 'Terry', 'Graham'])
191+
>>> queue.appendleft("John") # John is added to front of queue
192+
>>> queue
193+
deque(['John', 'Michael', 'Terry', 'Graham'])
191194

192195

193196
.. _tut-listcomps:

0 commit comments

Comments
 (0)