Guided Project - App Recommendation if function question

I’m working on the Guided Project for the App Recommendations and I’m confused how the bolded section(s) below work. We don’t define ‘genre’ here, so how does it know what to do /pull? I tried replacing the word with others and I see that I get the same result from running the code by replacing the bold ‘genre’ with ‘test’ or ‘blah’. I would greatly appreciate someone explaining how/why this works please?
prime_genre_freq = freq_table(ios_final, 11)
for genre in prime_genre_freq:
total = 0
len_genre = 0
for row in ios_final:
genre_app = row[11]
if genre_app == genre:
n_ratings = float(row[5])
total += n_ratings
len_genre += 1
avg_user_ratings = total / len_genre
print(genre, ‘:’, avg_user_ratings)

@japoirier1

Welcome to the community!

Let’s assume that you have the following list and want to view the item inside the list one after the other:

my_list = [1, 2, 3, 4]

for one_item in my_list:
    print(one_item)

# Output:
1
2
3
4

The one_item is a placeholder you dynamically pass items in my_list through. This means that if you change the name of the placeholder from one_item to test, it will still work.

Thank you. This makes sense to me now when I’m looking at these.

1 Like