I have a list of dictionaries:
persons = [{'id': 1, 'name': 'john'},
{'id': 2, 'name': 'doe'},
{'id': 3, 'name': 'paul'}]
ids = [1,3]
# remove_persons(persons, ids) --> [{'id': 2, 'name': 'doe'}]
I would like to remove dictionaries from a list of id.
What is the most efficient way to go about this programmatically.
>Solution :
I think this will do the jobs
persons = [{'id': 1, 'name': 'john'},
{'id': 2, 'name': 'doe'},
{'id': 3, 'name': 'paul'}]
ids = [1, 3]
persons = [person for person in persons if person['id'] not in ids]
print(persons)
print(persons)
but i dont know about the performance