From 5cb38d1549ffb2a1f4bdcb4a98f51842db163230 Mon Sep 17 00:00:00 2001 From: Lubomir Pamukov Date: Fri, 17 Oct 2025 22:00:35 +0300 Subject: [PATCH 1/4] Add remove() method documentation for deque --- .../concepts/deque/terms/remove/remove.md | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 content/python/concepts/deque/terms/remove/remove.md diff --git a/content/python/concepts/deque/terms/remove/remove.md b/content/python/concepts/deque/terms/remove/remove.md new file mode 100644 index 00000000000..caf6b8edc73 --- /dev/null +++ b/content/python/concepts/deque/terms/remove/remove.md @@ -0,0 +1,75 @@ +--- +Title: 'remove()' +Description: 'Removes the first occurrence of a specified value from a deque.' +Subjects: + - 'Computer Science' + - 'Data Structures' +Tags: + - 'Deque' + - 'Methods' + - 'Data Structures' +CatalogContent: + - 'learn-python-3' + - 'paths/computer-science' +--- + +# remove() + +The **`remove()`** method removes the first occurrence of a specified value from a **deque**. If the value is not found in the deque, a `ValueError` is raised. The method modifies the deque in-place and does not return a value. + +## Syntax + +``` +deque.remove(value) +``` + +### Parameters + +| Parameter | Type | Description | +|-----------|------|-------------| +| `value` | Any | The item to be removed from the deque. Only the first occurrence is removed. | + +### Return Value + +The `remove()` method returns `None`. + +### Exceptions + +- **`ValueError`**: Raised when the specified value is not found in the deque. + +## Example + +```python +from collections import deque + +# Create a deque with integer elements +numbers = deque([10, 20, 30, 20, 40]) + +# Remove the first occurrence of 20 +numbers.remove(20) + +print(numbers) # Output: deque([10, 30, 20, 40]) +``` + +In the example above, the `remove()` method removes only the first occurrence of `20` from the deque, leaving the second occurrence of `20` intact. + +## Codebyte + +```codebyte/python +from collections import deque + +# Create a deque with string elements +colors = deque(['red', 'blue', 'green', 'blue', 'yellow']) + +print('Original deque:', colors) + +# Remove the first occurrence of 'blue' +colors.remove('blue') + +print('After remove("blue"):', colors) + +# Remove another element +colors.remove('red') + +print('After remove("red"):', colors) +``` \ No newline at end of file From 5fc20a8555f8ea36aec01263c50ce16bdb6943e7 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Mon, 20 Oct 2025 16:06:41 +0530 Subject: [PATCH 2/4] minor fixes --- .../concepts/deque/terms/remove/remove.md | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/content/python/concepts/deque/terms/remove/remove.md b/content/python/concepts/deque/terms/remove/remove.md index caf6b8edc73..241bb52c0e4 100644 --- a/content/python/concepts/deque/terms/remove/remove.md +++ b/content/python/concepts/deque/terms/remove/remove.md @@ -5,41 +5,39 @@ Subjects: - 'Computer Science' - 'Data Structures' Tags: + - 'Data Structures' - 'Deque' - 'Methods' - - 'Data Structures' CatalogContent: - 'learn-python-3' - 'paths/computer-science' --- -# remove() - -The **`remove()`** method removes the first occurrence of a specified value from a **deque**. If the value is not found in the deque, a `ValueError` is raised. The method modifies the deque in-place and does not return a value. +The **`remove()`** method removes the first occurrence of a specified value from a deque. If the value is not found in the deque, a `ValueError` is raised. The method modifies the deque in-place and does not return a value. ## Syntax -``` +```pseudo deque.remove(value) ``` -### Parameters +**Parameters:** -| Parameter | Type | Description | -|-----------|------|-------------| -| `value` | Any | The item to be removed from the deque. Only the first occurrence is removed. | +- `value`: The item to be removed from the deque. Only the first occurrence is removed. -### Return Value +**Return value:** The `remove()` method returns `None`. -### Exceptions +**Exceptions:** + +- `ValueError`: Raised when the specified value is not found in the deque. -- **`ValueError`**: Raised when the specified value is not found in the deque. +## Example: Removing an Element by Value -## Example +In this example, the first occurrence of a given value is removed from the deque: -```python +```py from collections import deque # Create a deque with integer elements @@ -48,12 +46,20 @@ numbers = deque([10, 20, 30, 20, 40]) # Remove the first occurrence of 20 numbers.remove(20) -print(numbers) # Output: deque([10, 30, 20, 40]) +print(numbers) +``` + +The output of the code is: + +```shell +deque([10, 30, 20, 40]) ``` In the example above, the `remove()` method removes only the first occurrence of `20` from the deque, leaving the second occurrence of `20` intact. -## Codebyte +## Codebyte Example + +In this example, multiple elements are removed one at a time from the deque. ```codebyte/python from collections import deque @@ -72,4 +78,4 @@ print('After remove("blue"):', colors) colors.remove('red') print('After remove("red"):', colors) -``` \ No newline at end of file +``` From 56c7620f4d943a2af18cb987f4c9c93570e32bf1 Mon Sep 17 00:00:00 2001 From: Daksha Deep Date: Wed, 22 Oct 2025 14:41:45 +0530 Subject: [PATCH 3/4] Update remove.md --- content/python/concepts/deque/terms/remove/remove.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/python/concepts/deque/terms/remove/remove.md b/content/python/concepts/deque/terms/remove/remove.md index 241bb52c0e4..26685abf036 100644 --- a/content/python/concepts/deque/terms/remove/remove.md +++ b/content/python/concepts/deque/terms/remove/remove.md @@ -13,7 +13,7 @@ CatalogContent: - 'paths/computer-science' --- -The **`remove()`** method removes the first occurrence of a specified value from a deque. If the value is not found in the deque, a `ValueError` is raised. The method modifies the deque in-place and does not return a value. +The **`remove()`** method removes the first occurrence of a specified value from a [deque](https://www.codecademy.com/resources/docs/python/collections-module/deque). If the value is not found in the deque, a `ValueError` is raised. The method modifies the deque in-place and does not return a value. ## Syntax From 42195e8fd6b2675d5b7e0d1b6519fb6022b02fba Mon Sep 17 00:00:00 2001 From: Daksha Deep Date: Wed, 22 Oct 2025 14:43:38 +0530 Subject: [PATCH 4/4] Update remove.md --- content/python/concepts/deque/terms/remove/remove.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/python/concepts/deque/terms/remove/remove.md b/content/python/concepts/deque/terms/remove/remove.md index 26685abf036..d01568065d1 100644 --- a/content/python/concepts/deque/terms/remove/remove.md +++ b/content/python/concepts/deque/terms/remove/remove.md @@ -35,7 +35,7 @@ The `remove()` method returns `None`. ## Example: Removing an Element by Value -In this example, the first occurrence of a given value is removed from the deque: +In this example, the first occurrence of a given value is removed from the `deque`: ```py from collections import deque @@ -59,7 +59,7 @@ In the example above, the `remove()` method removes only the first occurrence of ## Codebyte Example -In this example, multiple elements are removed one at a time from the deque. +In this example, multiple elements are removed from the deque, one at a time: ```codebyte/python from collections import deque