Extracting information depending on user input from a dictionary
<p>I have the following information from a <a href="http://www.futbin.com/api?term=paul%20pogba" rel="nofollow">.json</a> loaded and stored in a variable <code>Data</code>:</p>

<pre><code>Data = [
    {u'rating': u'89', u'rare': u'1', u'name': u'Pogba', u'club_image': u'/content/fifa17/img/clubs/11.png', u'image': u'/content/fifa17/img/players/195864.png', u'rare_type': u'3', u'version': u'IF', u'full_name': u'Pogba', u'position': u'CDM', u'id': u'15073', u'nation_image': u'/content/fifa17/img/nation/18.png'},
    {u'rating': u'89', u'rare': u'1', u'name': u'Pogba', u'club_image': u'/content/fifa17/img/clubs/11.png', u'image': u'/content/fifa17/img/players/195864.png', u'rare_type': u'21', u'version': u'OTW', u'full_name': u'Pogba', u'position': u'CM', u'id': u'15091', u'nation_image': u'/content/fifa17/img/nation/18.png'},
    {u'rating': u'88', u'rare': u'1', u'name': u'Pogba', u'club_image': u'/content/fifa17/img/clubs/11.png', u'image': u'/content/fifa17/img/players/195864.png', u'rare_type': u'1', u'version': u'Normal', u'full_name': u'Pogba', u'position': u'CM', u'id': u'78', u'nation_image': u'/content/fifa17/img/nation/18.png'}
]
</code></pre>

<p>I'd like to extract the information depending on the <code>rating</code> of the player inputted by the user, only if <em>another rating exists</em>. <em>EDIT</em> : <em>By this, I mean that if only one line was present, i.e. 1 rating, there would be no need to carry out the process.</em></p>

<p>For example, if the user inputted: <code>88</code>, it would return/print:</p>

<pre><code>{u'rating': u'88', u'rare': u'1', u'name': u'Pogba', u'club_image': u'/content/fifa17/img/clubs/11.png', u'image': u'/content/fifa17/img/players/195864.png', u'rare_type': u'1', u'version': u'Normal', u'full_name': u'Pogba', u'position': u'CM', u'id': u'78', u'nation_image': u'/content/fifa17/img/nation/18.png'}
</code></pre>

<p>From my minimal knowledge, I am aware that I must use dictionaries, but am unaware of how to do so. However, I am currently in the following stage in my attempts:</p>

<pre><code>player_dict = {Data}
player_info = player_dict.get(user_input)
if player_info:
    for item in player_info:
        player_info = item
</code></pre>

<p>^ <em>This doesn't seem to work at all.</em></p>

<p>Well in this case, you need to loop over your values and compare the one that has been input to the ones you already have, right?</p>

<p>So <code>player_dict</code> is a list of dictionaries, and every dictionary contains properties about a player, of which <code>rating</code> is one.
Also, let's say that <code>player_info</code> is the user-inputted rating, like <code>88</code>.</p>

<pre><code>for player_dict in player_dict:
    try:
         if player_dict['rating']==player_info:
              return player_dict
    except KeyError:
         print 'there is no key called rating in this dict!'
</code></pre>

python json python-2.7 dictionary