Dict KeyError for value in the dict

前端 未结 4 1796
Happy的楠姐
Happy的楠姐 2021-01-20 02:02

I have a dict inside a dict:

{
\'123456789\': {u\'PhoneOwner\': u\'Bob\', \'Frequency\': 0},
\'98765431\': {u\'PhoneOwner\': u\'Sarah\', \'Frequency\': 0},
         


        
4条回答
  •  离开以前
    2021-01-20 02:21

    You are attempting to search for a key that is an integer:

    phoneNumberDictionary[int(line)]
    

    However, your dictionary is defined with your phone numbers as strings.

    '123456789'
    

    Thus, the key with integer 123456789 doesn't exist.

提交回复
热议问题