From 82f349bffe32b4eca0fbe1001f7096773a58c926 Mon Sep 17 00:00:00 2001 From: Asutosh Date: Fri, 6 Oct 2017 16:39:55 +0530 Subject: [PATCH 1/3] updated comment for .remove() in case if there are multiple entries of the passed value, the .remove() method only removes the first occurrence of the passed value. --- arrays/array.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arrays/array.py b/arrays/array.py index 0d54968..a376048 100644 --- a/arrays/array.py +++ b/arrays/array.py @@ -11,7 +11,7 @@ def array_test(): print(ar) print("Index of 4: ", ar.index(4)) # index of given value - ar.remove(4) # remove item with given value + ar.remove(4) # remove the first occurence of item with given value print("Removed 4: ", ar) ar.reverse() From 73b91f78d6705d6d8215dcb3296317aee1da6caf Mon Sep 17 00:00:00 2001 From: ifbizo Date: Tue, 21 Nov 2017 18:06:21 -0800 Subject: [PATCH 2/3] Delete all instances of value --- linked_lists/linked_list.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/linked_lists/linked_list.py b/linked_lists/linked_list.py index 9c8e1cd..61b57ce 100644 --- a/linked_lists/linked_list.py +++ b/linked_lists/linked_list.py @@ -52,10 +52,8 @@ def delete(self, value): prev.set_next(current.get_next()) else: self.head_ = current.get_next() - break - else: - prev = current - current = current.get_next() + prev = current + current = current.get_next() # Pushes an item on the front of the list. def push(self, value): From 083ce97fff39c627c29623980e3e888ca0f3083c Mon Sep 17 00:00:00 2001 From: Prasang-money <65109534+Prasang-money@users.noreply.github.com> Date: Sun, 11 Jul 2021 23:37:01 +0530 Subject: [PATCH 3/3] Update linked_list.py # Deletes all instances of given value in list. changes in that particular file when we are deleting a node in that particular case we do not need to update the prev value otherwise prev will be pointed to the deleted node. So in the updated code, we will update prev only if the current node value is not equal to the target value. and the current node will be updated at every iteration --- linked_lists/linked_list.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/linked_lists/linked_list.py b/linked_lists/linked_list.py index 61b57ce..5d0c3ce 100644 --- a/linked_lists/linked_list.py +++ b/linked_lists/linked_list.py @@ -52,7 +52,8 @@ def delete(self, value): prev.set_next(current.get_next()) else: self.head_ = current.get_next() - prev = current + else + prev = current current = current.get_next() # Pushes an item on the front of the list.