The excercise starts by creating a list called gamers = []. The list is called as a parameter in a few functions, but I fail to seewhere the list is populated and what values are passed on.
List item
This function is created to count the availability by night. But I don’t understand how the counted in a next funtion adds to this counter:
def build_daily_frequency_table():
return {
“Monday”: 0,
“Tuesday”: 0,
“Wednesday”: 0,
“Thursday”: 0,
“Friday”: 0,
“Saturday”: 0,
“Sunday”: 0,
}
def calculate_availability(gamers_list, available_frequency):
for gamer in gamers_list:
for day in gamer[‘availability’]:
available_frequency[day] += 1
Hi! Thank you so much for taking the time to go over this.
Regarding the “gamers= ” list. I did see the section “step 2”. I just didn’t mention it. In your code, I see that you populate the beforementioned list, but in the excercise, I do not see that happening. The instructions say that I am to "Create a function called add_gamer that takes two parameters: gamer and gamers_list . The function should check that the argument passed to the gamer parameter has both "name" and a "availability" as keys and if so add gamer to a list called gamers_list .
So this last instruxction tells me to append to “gamers_list”, not to the list created at the begining as ‘gamers’.
Regarding the frequency table, I can see (and understand the logic of it) the loop going over the availability and adding it to a list called “available_frequency”, but I don’t see that name defined earlier anywhere. I would expect this function (“calculate_availability”) to be related to the previous function, namely:
“def build_daily_frequency_table():
return {“Sunday”: 0, “Monday”: 0, “Tuesday”: 0, “Wednesday”: 0, “Thursday”: 0, “Friday”: 0, “Saturday”: 0}
count_availability = build_daily_frequency_table()”
Hey there! I totally get your confusion with the “gamers” list. In the exercise, you are asked to create a function called “add_gamer” that takes in two parameters - “gamer” and “gamers_list”. This function is supposed to check if the “gamer” parameter has both “name” and “availability” keys, and if so, add it to the “gamers_list” using the “append” method. So, you are correct that you need to append to “gamers_list” and not the list created at the beginning.
As for the frequency table, you’re right that the name “available_frequency” is not defined earlier in the code. However, the function “calculate_availability” takes in the “gamers_list” and the empty dictionary returned by the “build_daily_frequency_table” function, which is assigned to the variable “count_availability”. Within the “calculate_availability” function, there’s a loop that iterates over each gamer’s availability and increments the count for the corresponding day in “available_frequency”, which is actually the same dictionary as “count_availability”. So, the frequency counts are added to the dictionary created in “build_daily_frequency_table”.
I hope this explanation helps! Let me know if you have any other questions or concerns, and I’ll be happy to help.
Hi!
Thanks again. I think that I am narrowing down my doubts. So, the list “gamers” which is a parameter of each players’ dictionary and is later present in:
“def available_on_night(gamers_list, day):
return [gamer for gamer in gamers_list if day in gamer[‘availability’]]
attending_game_night = available_on_night(gamers, game_night)
print(attending_game_night)”
What is its role? I can’t grasp it, although I see that it part of something
And regarding the second question, how can I come to the same conclusion that you do when you say that one dictionary is the same as the other in “Within the “calculate_availability” function, there’s a loop that iterates over each gamer’s availability and increments the count for the corresponding day in “available_frequency”, which is actually the same dictionary as “count_availability”.”