Skip to content

Instantly share code, notes, and snippets.

@artturijalli
Created May 12, 2022 15:03
Show Gist options
  • Save artturijalli/f90674879e6c02a04a7fcd57d516fb56 to your computer and use it in GitHub Desktop.
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
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