I have written code to extract record information from a folder of old csv files into dictionary A and a folder of new csv files into dictionary B. The dictionaries each look like the following with different filenames for each record indicating where the record(or row) that it came from:
{'MC1003-1513846743.67153296': {'row': 2, 'record': ['MC1003-1', '5138467', '43.67', '15', '', '', '', '', '', '', '', '', '', '', '3296'], 'file_name': 'Timecard-MC1003-1-20220425103004.csv'}, 'MC1003-1546339635.95153296': {'row': 3, 'record': ['MC1003-1', '5463396', '35.95', '15', '', '', '', '', '', '', '', '', '', '', '3296'], 'file_name': 'Timecard-MC1003-1-20220425103004.csv'}
I am trying to compare the two dictionaries each of which contain over a thousand different records coming from old and new folder. What is the best way to find if a record in dictionary A is not present in dictionary B and do the same the other way around i.e check if a record in dictionary B is not present in dictionary A. Can someone please help me! I am struggling to find a solution? The code I have written below in theory should look at all the records in dictionary B, compare each one of them with the record in dictionary A, and output the record if it doesn't match the specific records being compared. However, I want to output a record from dictionary A only if it doesn't match any of the records in dictionary B. Right now, it outputs all the records for some reason. Please let me know what I am doing wrong? Here dir_A_dict and dir_B_dict are the dictionaries that I have read in.
for a in dir_A_dict.keys():
row_a = dir_A_dict[a].get('row')
result_a = dir_A_dict[a].get('record')
name_a = dir_A_dict[a].get('file_name')
for b in dir_B_dict.keys():
row_b = dir_B_dict[b].get('row')
result_b = dir_B_dict[b].get('record')
name_b = dir_B_dict[b].get('file_name')
if result_a != result_b:
print("Record", result_a,"in file",name_a, "is different from", result_b,"in file", name_b)
The output for this code comes out to be like this. In this case since the record in dictionary A is clearly present in dictionary B, the code should go to the next record in dictionary A and find if that record is present in dictionary B as well or not:
Record ['MC1003-1', '5138467', '43.67', '15', '', '', '', '', '', '', '', '3296'] in file Timecard-MC1003-1-20220425100254-Reported.csv is different from ['MC1003-1', '5138467', '43.67', '15', '', '', '', '', '', '', '', '', '', '', '3296'] in file Timecard-MC1003-1-20220425103004.csv
Record ['MC1003-1', '5138467', '43.67', '15', '', '', '', '', '', '', '', '3296'] in file Timecard-MC1003-1-20220425100254-Reported.csv is different from ['MC1003-1', '5463396', '35.95', '15', '', '', '', '', '', '', '', '', '', '', '3296'] in file Timecard-MC1003-1-20220425103004.csv