bookrecs.py - Name Book Recommendations Author Ethan...

This preview shows page 1 - 2 out of 2 pages.

''' Name: Book Recommendations Author: Ethan Balling Due Date: 28 Jan 2021 Course: CS1410-001 Details: The program will take a single reader's name and compare their book preferences to others and return book recommendations from two other readers with similar tastes. This is done by comparing the specified reader's book ratings with a lists of readers and their ratings for books theyve read to find the two readers with or the highest affinity score(dot product). The list will then be sorted and return the books that the specified reader hasn't read yet. ''' # import needed methods. from heapq import nlargest ''' Create a list of tuples from provided file, each tuple contains an author and book title. ''' booklist = [] with open("booklist.txt") as file_in: booklist = [tuple(line.strip().split(',')) for line in file_in] ''' Create a dictionary from provided file, each key:value pair contains a readers name and a list of their book ratings. ''' reader_ratings = {} with open("ratings.txt") as file_in: for key in file_in: reader_ratings[key.strip().lower()] = [int(i) for i in

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture