I have some code for car registration for parking. I have created a dictionary with car registration number as keys and rest information as values. I am trying to get details (values) of each registration by entering the registration number. Even if the id is in the dictionary it's showing message not found in the dictionary.
global variable data_dict = {} def createNameDict(filename): path = "C:\Users\user\Desktop" basename = "ParkingData_Part2.txt" filename = path + "\\" + basename file = open(filename) contents = file.read() print contents,"\n" data_list = [lines.split(",",1) for lines in contents.split("\n")] #data_list.sort() #print data_list #dict_list = [] for line in data_list: keys = line[0] values = line[1] data_dict[keys] = values print data_dict,"\n" print data_dict.keys(),"\n" print data_dict.values(),"\n" print data_list def detailForRegistrationNumber(regNumber): regNumber == "keys" if regNumber in data_dict: print data_dict[regNumber] else: print regNumber, "Not in dictionary" The error message I am getting is:
======= Loading Progam ======= >>> detailForRegistrationNumber('EDF768') EDF768 Not in dictionary But the dictionary has the above registration number:
{'HUY768': ' Wilbur Matty, 8912, Creche_Parking', 'GH7682': ' Clara Hill, 7689, AgHort_Parking', 'GEF123': ' Jill Black, 3456, Creche_Parking', 'WER546': ' Olga Grey, 9898, Creche_Parking', 'TY5678': ' Jane Miller, 8987, AgHort_Parking', 'ABC234': ' Fred Greenside, 2345, AgHort_Parking', 'KLOI98': ' Martha Miller, 4563, Vet_Parking', **'EDF768'**: ' Bill Meyer, 2456, Vet_Parking', 'JU9807': ' Jacky Blair, 7867, Vet_Parking', 'DF7800': ' Jacko Frizzle, 4532, Creche_Parking', 'ADF645': ' Cloe Freckle, 6789, Vet_Parking'}
r'C:\whatever\path'