# how to remove all instances of a character from a list python

75 views

## Problem :

How to remove all occurrences of a value from a list?

I tried in Python remove() will remove the first occurrence of value in a list. How to remove all occurences?

## Solution :

Functional Approach:

2.x

```>>> x = [1,2,3,2,2,2,3,4]
>>> filter(lambda a: a != 2, x)
[1, 3, 3, 4]```

3.x

```>>> x = [1,2,3,2,2,2,3,4]
>>> list(filter((2).__ne__, x))
[1, 3, 3, 4]```

OR

```>>> x = [1,2,3,2,2,2,3,4]
>>> list(filter(lambda a: a != 2, x))
[1, 3, 3, 4]
```

## Related questions

7 views
Problem: How to remove all occurrences of a value from a list?
50 views
Problem: I am a newbee in python programming. I tried to remove all occurrences of a character in a list python. So I wrote a code: Nums = [11, 22, 11, 33, 11, 44, 11, 55] a = 11 print ("Original Numbers:") print (Nums) i=0 length = len(Nums) while(i< ... line 8, in <module> if(Nums[i]==a): IndexError: list index out of range Why I am getting this output but not the actual result. Please help
9 views
Problem: Please offer me an answer to the problem >Which method is used to remove all the elements from a list?
23 views
Problem: have a list of lists in Python: k = [[1, 2], [4], [5, 6, 2], [1, 2], [3], [4]] And I want to remove duplicate elements from it. Was if it a normal list not of lists I could used set. But unfortunate that list is not hashable and can't ... [3], [4]] I don't care about preserve order. Note: this question is similar but not quite what I need. Searched SO but didn't find exact duplicate.
3 views
8 views
Problem: how to I Solve this: remove a list from a list python HELP! I need help understanding this: remove a list from a list python Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
6 views
Problem: I need someone&rsquo;s assistance to solve my problem .. How to remove element from list in python