Sweety Sweety - 1 year ago 47
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}]]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download