From 811ef7446ef7e93db040d77f922898019187bb29 Mon Sep 17 00:00:00 2001 From: AdityaKrishnaProjects <137810299+AdityaKrishnaProjects@users.noreply.github.com> Date: Tue, 8 Oct 2024 11:23:27 -0500 Subject: [PATCH] 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. --- Doc/tutorial/datastructures.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Doc/tutorial/datastructures.rst b/Doc/tutorial/datastructures.rst index 73f17adeea72de..d9b9fa254cf916 100644 --- a/Doc/tutorial/datastructures.rst +++ b/Doc/tutorial/datastructures.rst @@ -188,6 +188,9 @@ have fast appends and pops from both ends. For example:: 'John' >>> queue # Remaining queue in order of arrival deque(['Michael', 'Terry', 'Graham']) + >>> queue.appendleft("John") # John is added to front of queue + >>> queue + deque(['John', 'Michael', 'Terry', 'Graham']) .. _tut-listcomps: