Skip to content

Instantly share code, notes, and snippets.

@okellogabrielinnocent
Created October 14, 2019 10:32
Show Gist options
  • Save okellogabrielinnocent/6876c31ac52375f74697936eaea26068 to your computer and use it in GitHub Desktop.
Save okellogabrielinnocent/6876c31ac52375f74697936eaea26068 to your computer and use it in GitHub Desktop.
# Transform the frequencies inside content_ratings to proportions and percentages while creating separate dictionaries for each.
# Assign the dictionary storing proportions to a variable named c_ratings_proportions.
# Assign the dictionary storing percentages to a variable named c_ratings_percentages.
# Optional challenge: try to solve this exercise using a single for loop (solution to this challenge provided).
content_ratings= {'4+': 4433, '12+': 1155, '9+': 987, '17+': 622}
total_number_of_apps = 7197
c_ratings_proportions = {}
c_ratings_percentages = {}
for key in content_ratings:
proportion = content_ratings[key] / total_number_of_apps
c_ratings_proportions[key] = proportion
for key in c_ratings_proportions:
percentage = c_ratings_proportions[key] * 100
c_ratings_percentages[key] = percentage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment