Guided Project: Hacker News Solutuion: When is hr a key, and when is it a value?

Screen Link:

The below code from cell 7 has me confused:

Calculate the average amount of comments Ask HN posts created at each hour of the day receive.
avg_by_hour =

for hr in comments_by_hour:
avg_by_hour.append([hr, comments_by_hour[hr] / counts_by_hour[hr]])

avg_by_hour

Can you explain why the first “hr” in this line ([hr, comments_by_hour[hr] / counts_by_hour[hr]]) refers to the key rather than the value?

Hi @BobDorris

avg_by_hour =  []
for hour in commentsperhour:
    avg_by_hour.append([hr, comments_by_hour[hr] / counts_by_hour[hr]])
avg_by_hour

In this code, you want to print a list with an hour and its corresponding average. So the final list will look something like this.

[ [‘09’, 5.5777777777777775],
[‘13’, 14.741176470588234],
[‘10’, 13.440677966101696],
[‘14’, 13.233644859813085],
[‘16’, 16.796296296296298] ]

Because of the instructions to print it like this, we are using the above code. I hope it makes sense.

Also it would be great if you can use this guide while posting technical questions.