Question: I have a data structure that looks like this

```
[{'name': 'sfsdf sdfsdf', 'id': '621205528'},
 {'name': 'test name', 'id': '32324234234'},
 {'name': 'another name', 'id': '3434535342221'}]

```

Now I have a model called Profile where the id in the dictionary maps to the uid field in the model. 

I'd like to remove every entry in the list that exists in the database. Is there a elegant way of doing this, right now I have a bunch of for loops that have multiple calls to the db but that may not be the best way to do it.

Answer: 
```
ids = [x['id'] for x in my_list]
existing_ids = Profile.objects.filter(id__in=ids).values_list('id', flat=True)
result = filter(lambda elm: elm['id'] in existing_ids, my_list)

```
Assuming there are not hundreds of records to delete, you can use the below.

```
objs = [{'name': 'sfsdf sdfsdf', 'id': '621205528'}, ...]

Profile.objects.filter(id__in=[x.get('id') for x in objs]).delete()

```