How can I get values from dictionary for particular key using python
<p>In this code, I wanted to identify a member with his ID. If the ID exist in the dictionary, I would like to print the fullname of this member</p>

<pre><code>iin = input('Enter your ID :')
 dict = {'id' : ['aa', 'bb', 'cc'],
        'Firstname' : ['Mark', 'Jamal', 'Van'],
        'Lastname' : ['Roch', 'borh', 'nilsa']}
 for d in dict:
    if inn in d:
       print('Hello,', dict[inn])
    else :
       print('Sorry, you are not a member')
</code></pre>

<p>The desired result</p>

<pre><code>Enter your ID : aa
Hello, Mark Roch
</code></pre>

<p>Thank you for the help</p>

<p>Building on <a href="http://stackoverflow.com/questions/176918/finding-the-index-of-an-item-given-a-list-containing-it-in-python">previous posts</a></p>

<pre><code>iin = input('Enter your ID :')
dict = {'id' : ['aa', 'bb', 'cc'],
        'Firstname' : ['Mark', 'Jamal', 'Van'],
        'Lastname' : ['Roch', 'borh', 'nilsa']}
try:
    i = dict['id'].index(iin)
    print('Hello {0} {1}'.format(dict['Firstname'][i], dict['Lastname'][i])
except ValueError:
    print('Sorry, you are not a member')
</code></pre>

<p><strong>NOTE</strong>: you cannot name a dictionary <code>dict</code> because it conflicts with a keyword.</p>

python for-loop dictionary input output