Consider eliminating value variable to improve performance
Opened this issue · 0 comments
karl-project-review commented
https://github.com/thomasoup/TomeRater/blob/e02a08af7b9f077581d5ec28f915f1c856865965/TomeRater.py#L269-L275
Since value == valueToRemove.title and it isn't used until we exit the for loop, we can skip assigning this variable every time we find a new temporary best and instead just access it from the valueToRemove variable at the end of the for loop. This should eliminate some unnecessary assignments and make the code a little more efficient. Here is an example:
for i in new_dict:
if new_dict[i] > total:
valueToRemove = i
total = self.books[i]
ordered_lst.append(valueToRemove.title)
new_dict.pop(valueToRemove)