Q:

Remove dict from list of dict if key and value doesnt match with other dict

I have a list of dictionaries and I want to filter it by values from other dictionary. 
orig_list = [{"name":"Peter","last_name":"Wick","mail":"Peter@mail.com","number":"111"},
{"name":"John","last_name":"Hen","mail":"John@mail.com","number":"222"},
{"name":"Jack","last_name":"Malm","mail":"Jack@mail.com","number":"542"},
{"name":"Anna","last_name":"Hedge","mail":"Anna@mail.com"},
{"name":"Peter","last_name":"Roesner","mail":"Peter2@mail.com","number":"445"},
{"name":"Tino","last_name":"Tes","mail":"Tino@mail.com","number":"985"},]

expected result example 1:
filter = {"name":"Peter"}

orig_list[{"name":"Peter","last_name":"Wick","mail":"Peter@mail.com","number":"111"},
{"name":"Peter","last_name":"Roesner","mail":"Peter2@mail.com","number":"445"}]

expected result example 2:
filter = {"name":"Peter","number":"445"}

orig_list[
{"name":"Peter","last_name":"Roesner","mail":"Peter2@mail.com","number":"445"}]

The filter can have multiple keys. possible keys are(name,last_name,number).
Basically what I want, is to go through the list of dict and check every dict if the dict contains key from given filter and if it does, check if the key values match. If they dont, remove the whole dict from the list of dict.
The final list does not have to be the orig_list. It can be a new list. So its not mandatory to delete dicts from the orig_list. The dicts can be also copied to new list of dicts.

A:

You can use list comprehension:
orig_list = [{"name":"Peter","last_name":"Wick","mail":"Peter@mail.com","number":"111"},
{"name":"John","last_name":"Hen","mail":"John@mail.com","number":"222"},
{"name":"Jack","last_name":"Malm","mail":"Jack@mail.com","number":"542"},
{"name":"Anna","last_name":"Hedge","mail":"Anna@mail.com"},
{"name":"Peter","last_name":"Roesner","mail":"Peter2@mail.com","number":"445"},
{"name":"Tino","last_name":"Tes","mail":"Tino@mail.com","number":"985"},]

filter_by = {"name":"Peter"}

result = [dic for dic in orig_list if all(key in dic and dic[key] == val for key, val in filter_by.items())]
print(result)

Output:
[
  {
    "name": "Peter",
    "last_name": "Wick",
    "mail": "Peter@mail.com",
    "number": "111"
  },
  {
    "name": "Peter",
    "last_name": "Roesner",
    "mail": "Peter2@mail.com",
    "number": "445"
  }
]

For filter_by = {"name":"Peter","number":"445"} you get:
[
  {
    "name": "Peter",
    "last_name": "Roesner",
    "mail": "Peter2@mail.com",
    "number": "445"
  }
]

