Page view counter
Easyclassdictionary attributesorted· 10 XP
A website keeps a running count of page views while it runs, and an admin screen shows the most viewed pages.
Write a class ViewCounter with:
view(page)that adds one view to that pageviews(page)that returns the number of views for a page (0 if it was never viewed)top(n)that returns a list of thenmost viewed pages, most views first, breaking ties alphabetically
How it's checked
Your code runs, then the check below runs and its printed output is compared with ours.
- After viewing
"/home"twice and"/cart"once,top(1)returns["/home"]
Hints, the later questions and the answer come with Pro.
class ViewCounter:
def __init__(self):
...