Created
May 12, 2022 15:03
-
-
Save artturijalli/f90674879e6c02a04a7fcd57d516fb56 to your computer and use it in GitHub Desktop.
Remove all occurrences of a specific value from a list using a while loop in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
numbers = [1, 4, 4, 26, 4, 4, 8, 0, 4] | |
target = 4 | |
i = 0 | |
while i < len(numbers): | |
if numbers[i] == target: | |
numbers.pop(i) | |
i -= 1 | |
i += 1 | |
print(numbers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment