-1

I want to remove all occurrences of a list from list of lists. By that I mean I want to filter out all the occurrences of a given list. E.g.

list = [[1,2,3], [3,2,1] ,[4,2,5],[1,2,3]]
list.removeList([1,2,3])
list=[[3,2,1],[4,2,5]]

I was thinking of using a filter or .remove() but it is giving me error. And for the filter I don't know what approach I should start with

2 Answers2

1

Use a list comprehension

l = [sublist for sublist in l if sublist != [1, 2, 3]]
Barmar
  • 741,623
  • 53
  • 500
  • 612
0
list1 = [[1,2,3], [3,2,1] ,[4,2,5],[1,2,3]]
list2= list1

for i in list1:
    if i==[1,2,3]:
        list2.remove(i)

With append

list1 = [[1,2,3], [3,2,1] ,[4,2,5],[1,2,3]]
list2= []

for i in list1:
    if i!=[1,2,3]:
        list2.append(i)
ombk
  • 2,036
  • 1
  • 4
  • 16