Sweety Sweety - 1 month ago 12
Python Question

how to remove all occurences of particular lists from lists of list

I want to remove all

[{'id': -1}]
lists from following list:

>>> a = [[{'bugs': []}], [{'id': -1}], [{'bugs': []}], [{'bugs': []}], [{'id': -1}], [{'id': -1}]]


I tried with
remove
which removed first
[{'id': -1}]
list:

>>> a.remove([{'id': -1}])


How can I remove all the occurences of
[{'id': -1}]
?

>>> a
[[{'bugs': []}], [{'bugs': []}], [{'bugs': []}], [{'id': -1}], [{'id': -1}]]

Answer Source
l = [item for item in a if item != [{"id": -1}]]