Python remove dictionaries from list
<p>Python listed dictionaries:</p>

<pre><code>_list_ = [{'key1': 'value1', 'key2': 'value2'}, {'key1': 'value3', 'key2': 'value4'}]

example_search_str1 = 'e1' # for value1 of key1

example_search_str2 = 'e3' # for value3 of key1
</code></pre>

<p>I want to delete listed dictionaries containing multiple example search strings. How to achieve this? Existing answers didn't help much. Python newbie here.</p>

<p>Also for matching (key, unwanted_value) I would maybe try smthng like:</p>

<pre><code>list_of_dicts =  [{'key1': 'value1', 'key2': 'value2'}, {'key1': 'value3', 'key2': 'value4'}]
bad_keys_vals = [('key1', 'value1'), ('key2', 'value2')]


def filter_dict_list(list_of_dicts, bad_keys_vals):
    return list(filter(lambda d: any((d[key] != bad_val for key, bad_val in bad_keys_vals)), list_of_dicts))

print(filter_dict_list(list_of_dicts, bad_keys_vals))
&gt;&gt; [{'key2': 'value4', 'key1': 'value3'}]
</code></pre>

<p>But yes, this result in creating a new list, so you would probably need to overwright the old one.</p>

python list dictionary