Please help me understand the Codecademy solution code for Step 8 in the project at https://www.codecademy.com/courses/learn-python-3/informationals/python3-abruptly-goblins
The Codecademy solution code is as follows …
def find_best_night(availability_table):
best_availability = 0
for day, availability in availability_table.items():
if availability > best_availability:
best_night = day
best_availability = availability
return best_night
Compare to my code …
def find_best_night(availability_table):
best_availability = 0
for day, count in count_availability.items():
if count > best_availability:
best_availability = count
best_night = day
return best_night
-
I don’t understand why the argument is supposed to be ‘availability_table’. I put in my argument as ‘count_availability’ (which was a dictionary that I correctly coded in the previous step) because I thought our code should be looping through the keys and values in this ‘count_availability’ dictionary to help us find the winning day. Moving on to the next step (Step 9) I see that this very dictionary ‘count_availability’ is supposed to be used to call the function find_best_night. Is ‘availability_table’ just some random name? It doesn’t matter what name we put inside as the argument? If it doesn’t matter, then why can’t we just leave the parenthesis empty?
-
Why is ‘availability_table.item()’ the dictionary that we .item()/loop through? We did not define ‘availability_table’ previously … so literally there’s nothing to loop through?!
-
In my code, I named the value ‘count’ (instead of ‘availability’ as seen in the Codecademy solution). Is that ok? Or does the value need to be designated as ‘availability’ because that’s the name we used up in Step 2?
Thank you for your help.