|
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).
CodeAcademyPythonIntensive/TomeRater.py
Lines 310 to 324 in 4bc35a9
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).