Skip to main content
edited title
Link
Setsuna
  • 2.1k
  • 7
  • 35
  • 51

How to properly delete items in a list from a list in python?

Source Link
Setsuna
  • 2.1k
  • 7
  • 35
  • 51

How to properly delete items in a list from a list in python?

Assuming I have the following list:

array1 = ['A', 'C', 'Desk']

and another array that contains:

array2 = [{'id': 'A', 'name': 'Greg'}, 
{'id': 'Desk', 'name': 'Will'},
{'id': 'E', 'name': 'Craig'},
{'id': 'G', 'name': 'Johnson'}]

What is a good way to remove items from the list? The following does not appear to work

for item in array2:
   if item['id'] in array1:
     array2.remove(item)