get dictionary contains in list if key and value exists
<p>How to get complete dictionary data inside lists. but first I need to check them if key and value is exists and paired.</p>

<pre><code>test = [{'a': 'hello'  , 'b': 'world', 'c': 1},
        {'a': 'crawler', 'b': 'space', 'c': 5},
        {'a': 'jhon'   , 'b': 'doe'  , 'c': 8}]
</code></pre>

<p>when I try to make it conditional like this</p>

<pre><code>if any((d['c'] is 8) for d in test):
</code></pre>

<p>the value is True or False, But I want the result be an dictionary like</p>

<pre><code>{'a': 'jhon', 'b': 'doe', 'c': 8}
</code></pre>

<p>same as if I do</p>

<pre><code>if any((d['a'] is 'crawler') for d in test):
</code></pre>

<p>the results is:</p>

<pre><code>{'a': 'crawler', 'b': 'space', 'c': 5}
</code></pre>

<p>Thanks before.</p>

<p>Use comprehension:</p>

<pre><code>data = [{'a': 'hello'  , 'b': 'world', 'c': 1},
        {'a': 'crawler', 'b': 'space', 'c': 5},
        {'a': 'jhon'   , 'b': 'doe'  , 'c': 8}]

print([d for d in data if d["c"] == 8])
# [{'c': 8, 'a': 'jhon', 'b': 'doe'}]
</code></pre>

python list if-statement dictionary condition