Dict KeyError for value in the dict
I have a dict inside a dict: { '123456789': {u'PhoneOwner': u'Bob', 'Frequency': 0}, '98765431': {u'PhoneOwner': u'Sarah', 'Frequency': 0}, } The idea is to scan a list of calls made by numbers and compare against the dict, increasing the frequency each time a match is found. When I run the script: try: phoneNumberDictionary[int(line)]['Frequency'] += 1 except KeyError: phoneNumberDictionary[int(line)]['Frequency'] = 1 I get error: KeyError: '18667209918' (Where 18667209918 is the number that is currently being searched) Yet when I print the dict and just search for that number I can find it