Python: return first value by condition of nested dictionary in array : <p>Have some array with nested dictionaries:<br>
<code>data = [{'id':1, 'name':'test'}, {'id':2, 'name':'test'}, ....., {'id':N, 'name':'test'}]</code></p>

<p>Trying to return first <code>id</code> value where <code>name=test</code>:  </p>

<p><code>val = [x['id'] for x in data if x['name'] == 'test'][0]</code>  </p>

<p>expected result: <code>val = 1</code></p>

<p>But having exception: <code>list index out of range</code><br>
What's wrong?</p>
