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>Your question is a little unclear, but as I understand it, you want to remove dictionaries from a list if their 'key1' value is one of some number of strings.</p>

<pre><code>bad_strings = ['e1', 'e3']
new_list = [d for d in old_list if d['key1'] not in bad_strings] 
</code></pre>

<p>EDIT:</p>

<p>Oh, I get it.  I was close.  You want to see if 'key1' value contains the forbidden strings.  also doable.</p>

<pre><code>new_list = [d for d in old_list if not any(bad in d['key1'] for bad in bad_strings)]
</code></pre>

python list dictionary