remove all occurrences of a character in a list python

Posted by Paidboom - 6 months ago

remove all occurrences of a character in a list python : Using list. remove() function. list. Using List Comprehension. The recommended solution is to use list comprehension. Using filter() function.

if __name__ == '__main__':

l = [0, 1, 0, 0, 1, 0, 1, 1]
val = 0
l.remove(val)
print(l)  # prints [1, 0, 0, 1, 0, 1, 1]