Case: I need to get user input of employee ID using input()
to view employee details contained in a dictionary.
Problem: But the output of input()
is a string. How can I relate an employee ID to lookup for their information already contained in a dictionary. I try to use LIST but not successful.
Code:
Given list of Dictionary (employee ID number) containing employee detail
ID001 ={'Name':'John Clause', 'Age':'21' , 'Gender':'Male'}
ID002 ={'Name':'Greg Pyuse' , 'Age':'21' , 'Gender':'Male'}
Populate List with dictionary"
List = [ID001,ID002]
Require a user input() to ask for Dictionary i.e. 'ID001' or 'ID002'
ID = input()
I want to display list index corresponding to dictionary fron user input
ID_Index=List.index(ID)
If I run:
ValueError Traceback (most recent call last) in 3 4 #Get the list index of ID Number ----> 5 ID_Index=List.index(ID) 6 print(type(ID)) 7 #Display content of list with particular index
ValueError: 'ID002' is not in list