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>There's no need to loop over all the items in the dictionary; it would be silly to look for an id in the <code>Firstname</code> and <code>Lastname</code> fields.  (And this could produce incorrect results if the entered id happens to be a substring of someone's name.)</p>

<p>What you want is to check if the given id is present in the id list, and if so, use that list position to print the corresponding first and last names:</p>

<pre><code>if iin in dict['id']:
   index = dict['id'].index(iin)
   print('Hello, %s %s' % (dict['Firstname'][index], dict['Lastname'][index]))
else :
   print('Sorry, you are not a member')
</code></pre>

<p>Some suggestions:</p>

<p>It might be easier if you arranged your data as a list of dicts each containing a single member, like so:</p>

<pre><code>members = [
    {'id': 'aa', 'Firstname': 'Mark',  'Lastname': 'Roch'},
    {'id': 'bb', 'Firstname': 'Jamal', 'Lastname': 'borh'},
    {'id': 'cc', 'Firstname': 'Van',   'Lastname': 'nilsa'},
]
</code></pre>

<p>Don't name your dictionary <code>dict</code>, as that conflicts with a built-in function name.</p>

python for-loop dictionary input output