From a8f4e96ba7a737994eb7bdfc539695227c3d218c Mon Sep 17 00:00:00 2001 From: Aaravthk Date: Wed, 15 Oct 2025 14:45:40 +0530 Subject: [PATCH 1/3] Added pop.md --- .../python/concepts/deque/terms/pop/pop.md | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 content/python/concepts/deque/terms/pop/pop.md diff --git a/content/python/concepts/deque/terms/pop/pop.md b/content/python/concepts/deque/terms/pop/pop.md new file mode 100644 index 00000000000..e36f0f5e1b2 --- /dev/null +++ b/content/python/concepts/deque/terms/pop/pop.md @@ -0,0 +1,87 @@ +--- +Title: 'pop' # Required; the file name should be the same as the title, but lowercase, with dashes instead of spaces, and all punctuation removed +Description: 'Removes and returns element from the right end of the queue' # Required; ideally under 150 characters and starts with a present-tense verb (used in search engine results and content previews) +Subjects: # Please only use Subjects in the subjects.md file (https://github.com/Codecademy/docs/blob/main/documentation/subjects.md). If that list feels insufficient, feel free to create a new Subject and add it to subjects.md in your PR! + - 'Computer Science' + - 'Data Science' +Tags: # Please only use Tags in the tags.md file (https://github.com/Codecademy/docs/blob/main/documentation/tags.md). If that list feels insufficient, feel free to create a new Tag and add it to tags.md in your PR! + - 'Algorithms' + - 'Collections' + - 'Data Structures' + - 'Deques' +CatalogContent: # Please use course/path landing page slugs, rather than linking to individual content items. If listing multiple items, please put the most relevant one first + - 'learn-python-3' + - 'paths/computer-science' +--- + +**deque.pop()** Removes and returns an element from the right end of the deque. +If the deque is empty, calling ```pop()``` raises an ```IndexError``` +The ```pop()``` method works in O(1) time complexity - removing an element from either end of a deque is constant time. + + +## Syntax + +```pseudo +deque.pop() +``` + +**Parameters** + +This method does not take any parameters + +**Return Value** + +Returns the element that was removed from the right end of the deque + +**Exceptions** + +- ```IndexError``` - Raised if the deque is empty when ```pop()``` is called + +## Example + +This example demonstrates basic deque operation ```pop()``` + +```py +from collections import deque + +# Create a deque +dq = deque([10, 20, 30, 40]) + +# Remove and return the rightmost element +item = dq.pop() +print("Removed element:", item) +print("Deque after pop:", dq) +``` + +This example results in the following output + +```shell +Removed element: 40 +Deque after pop: deque([10, 20, 30]) +``` + + +## Codebyte Example: Popping the 2 rightmost element from deque + +This examples demonstrates the working of ```pop()``` + +```codebyte/python +from collections import deque + +# Create a deque with some numbers +numbers = deque([1, 2, 3, 4, 5]) + +print("Initial deque:", numbers) + +# Remove elements one by one from the right +last_item = numbers.pop() +print("Popped element:", last_item) +print("Deque after first pop:", numbers) + +# Pop again +another_item = numbers.pop() +print("Popped another element:", another_item) +print("Final deque:" numbers) +``` + + From 3eab2ee9dedaadeed18b5c33aaa7d325772768b4 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Thu, 16 Oct 2025 16:01:09 +0530 Subject: [PATCH 2/3] minor content fix, error in codebyte fixed --- .../python/concepts/deque/terms/pop/pop.md | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/content/python/concepts/deque/terms/pop/pop.md b/content/python/concepts/deque/terms/pop/pop.md index e36f0f5e1b2..1686153b885 100644 --- a/content/python/concepts/deque/terms/pop/pop.md +++ b/content/python/concepts/deque/terms/pop/pop.md @@ -1,23 +1,20 @@ --- -Title: 'pop' # Required; the file name should be the same as the title, but lowercase, with dashes instead of spaces, and all punctuation removed -Description: 'Removes and returns element from the right end of the queue' # Required; ideally under 150 characters and starts with a present-tense verb (used in search engine results and content previews) -Subjects: # Please only use Subjects in the subjects.md file (https://github.com/Codecademy/docs/blob/main/documentation/subjects.md). If that list feels insufficient, feel free to create a new Subject and add it to subjects.md in your PR! +Title: '.pop()' +Description: 'Removes and returns element from the right end of the deque.' +Subjects: - 'Computer Science' - 'Data Science' -Tags: # Please only use Tags in the tags.md file (https://github.com/Codecademy/docs/blob/main/documentation/tags.md). If that list feels insufficient, feel free to create a new Tag and add it to tags.md in your PR! +Tags: - 'Algorithms' - 'Collections' - 'Data Structures' - 'Deques' -CatalogContent: # Please use course/path landing page slugs, rather than linking to individual content items. If listing multiple items, please put the most relevant one first +CatalogContent: - 'learn-python-3' - 'paths/computer-science' --- -**deque.pop()** Removes and returns an element from the right end of the deque. -If the deque is empty, calling ```pop()``` raises an ```IndexError``` -The ```pop()``` method works in O(1) time complexity - removing an element from either end of a deque is constant time. - +The **`deque.pop()`** method removes and returns an element from the right end of a deque. Removing an element from either end of a deque occurs in O(1) time. ## Syntax @@ -27,19 +24,19 @@ deque.pop() **Parameters** -This method does not take any parameters +This method does not take any parameters. -**Return Value** +**Return value** -Returns the element that was removed from the right end of the deque +Returns the element that was removed from the right end of the deque. **Exceptions** -- ```IndexError``` - Raised if the deque is empty when ```pop()``` is called +- `IndexError`: Raised if the deque is empty when `.pop()` is called. ## Example -This example demonstrates basic deque operation ```pop()``` +In this example, a single element is removed from the right end of the deque using `.pop()`: ```py from collections import deque @@ -60,10 +57,9 @@ Removed element: 40 Deque after pop: deque([10, 20, 30]) ``` +## Codebyte Example: Popping the two rightmost elements -## Codebyte Example: Popping the 2 rightmost element from deque - -This examples demonstrates the working of ```pop()``` +In this example, elements are removed from the right end of a deque one by one using `.pop()`: ```codebyte/python from collections import deque @@ -81,7 +77,5 @@ print("Deque after first pop:", numbers) # Pop again another_item = numbers.pop() print("Popped another element:", another_item) -print("Final deque:" numbers) +print("Final deque:", numbers) ``` - - From 27e0d9f27f0fb7ce5f527f3b808fdfd0f879abaf Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Thu, 16 Oct 2025 16:01:59 +0530 Subject: [PATCH 3/3] Improve formatting in pop.md documentation Updated formatting for parameters, return value, and exceptions sections. --- content/python/concepts/deque/terms/pop/pop.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/content/python/concepts/deque/terms/pop/pop.md b/content/python/concepts/deque/terms/pop/pop.md index 1686153b885..80971cddde5 100644 --- a/content/python/concepts/deque/terms/pop/pop.md +++ b/content/python/concepts/deque/terms/pop/pop.md @@ -22,15 +22,15 @@ The **`deque.pop()`** method removes and returns an element from the right end o deque.pop() ``` -**Parameters** +**Parameters:** This method does not take any parameters. -**Return value** +**Return value:** Returns the element that was removed from the right end of the deque. -**Exceptions** +**Exceptions:** - `IndexError`: Raised if the deque is empty when `.pop()` is called.