I am completely lost at Guided Project: Profitable App Profiles for the App Store and Google Play Markets, part 10. Can somebody describe the solution code for me?

i need someone to describe me the solution, because i dont understand what it is asking for nor the structure. i reviewed the course but the content is different from what it is asked here. Very confusing.

The solution gives this:

def freq_table(dataset, index):
table = {} #i understand this, as the task is asking for a dictionary
total = 0 #what is this? why total = 0? where does it come from and for what??

for row in dataset:
    total += 1 **# does this mean that for every row in the dataset, sum "1" to the total value defined above?**
    value = row[index] #what does this pull exactly? value is the integer (index) of a row? 
    if value in table:
        table[value] += 1 #if there is a value in the table, it adds 1?
        table[value] = 1  #otherwise it stays as 1??

#please explain everything below:
table_percentages = {}
for key in table:
percentage = (table[key] / total) * 100
table_percentages[key] = percentage

return table_percentages

thank you in advance…i have been stuck here for a while and cannot find the logic/reasoning behind this solution. the task is not described properly at all either, in my opinion.

def display_table(dataset, index):
table = freq_table(dataset, index)
table_display =
for key in table:
key_val_as_tuple = (table[key], key)

table_sorted = sorted(table_display, reverse = True)
for entry in table_sorted:
    print(entry[1], ':', entry[0])

Hello @pati2msn! First off, please provide a link to the mission you struggle with and put all your code between triple backticks. You can read more about how to ask questions in the community guidelines.

Nonetheless, here is the explanation:

  • You are required to calculate the percentage of whatever value you find in the column at a certain index so of course, you have to count the total number of rows. That’s why you initialize total = 0 and then at every iteration of the for loop you increment this number by 1.
  • Your dataset is a list of lists so when you call row[index] you access a particular column at this index and return all the rows under this column. So if you write
for row in app_store_data:

You will return all the app ids with the header id. It works the same for the other columns.

  • So you choose your column and start to add key:value pair to your dictionary. If this value (for example, the name app) exists in you dictinary (as a key) you just update the current value for this key by adding 1, otherwise you create a new key (which name is the current value) and assign 1 to this key (since you’ve only encoutered it once).
  • To calculate the percentage of each value you just iterate over the keys in your dictinary table, take each value, divide it by the total number of rows and multiply by 100. Then you add this percentage to the dictionary table_percentage.


1 Like