Skip to content

Account for possibillity that n > len(self.books) #3

@karl-project-review

Description

@karl-project-review

def get_n_most_read_books(self, num):
n = 0
most_read = []
temp_dict = {}
for book, views in self.books.items():
temp_dict[book] = views
while n < num:
temp_max_view = max(temp_dict, key = temp_dict.get)
temp_dict.pop(temp_max_view)
most_read.append(temp_max_view)
n += 1
return most_read

Currently, if this function is passed a value for n that exceeds the number of books in the TomeRater library, the function will throw an error. Make sure to account for this possibility (like you did in your get_n_most_prolific_readers function in line 339).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions