In order to quickly compare the keys of 2 dictionaries, I'm creating sets of the keys using this method:
dict_1 = {"file_1":10, "file_2":20, "file_3":30, "file_4":40}
dict_2 = {"file_1":10, "file_2":20, "file_3":30}
set_1 = {file for file in dict_1}
set_2 = {file for file in dict_2}
Than I use diff_set = set_1 - set_2 to see which keys are missing from set_2.
Is there a faster way? I see that using set(dict.keys()) is less of a workarou, so I'll switch to it - but is it more efficient?
The fastest and most efficient way would be:
Output:
Proof(Execution time comparison):
Output: