idlist = ['101', '102']
myd = [
{'id':'101', 'role': 'tester'},
{'id':'102', 'role': 'tester'},
{'id':'103', 'role': 'tester'}
]
- I have
idlist - I need to check if a dictionary with the id is present in
myd - I need to remove the items with matching id
Expected output:
101 and 102 are deleted
[{'id':'103', 'role': 'tester'}]
Code is below
for ids in idlist:
for each in myd.items():
if ids == each['id']
del each
Do I need to do 2 for loop function to resolve this?
mydis a list somyd.items()won't do anything. You need to break down your problem into steps instead of trying to tackle everything at the same time.ids['id'] not in idlist.