I want to improve the performance of a huge code that works on logging files. In this file, there is a custom function that looks in a dictionary to find any key of a list of keys. However, in most cases the list includes only one key. So, my question is: If i replace this function with the built-in python method dict.get(key) will I see significant performance increase? The custom function is the following one:
def find_value(some_dict, list_of_keys):
for key in list_of_keys:
if key in some_dict:
field = some_dict[key]
else:
return None
return field
If I replace the above function with the common:
some_dict.get(keys[0])
in all cases that keys length is 1, will I see increase of performance? These cases are hundreds in the entire file and as they are found in loops, this function is executed many thousands even millions of times