Created
November 3, 2016 14:40
-
-
Save perilstar/2ae2f0f5b9364b41e4dce9a27d669f40 to your computer and use it in GitHub Desktop.
IMDB stuff created by ekyl - https://repl.it/ENqy/0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
class Episode: | |
def __init__(self, title, rating): | |
self.title = title | |
self.rating = rating | |
episodes = [] | |
episodes.append(Episode("Thing 1", 3.9)) | |
episodes.append(Episode("Thing 2", 7.3)) | |
episodes.append(Episode("Thing 3", 3.1)) | |
episodes.append(Episode("Thing 4", 8.3)) | |
episodes.append(Episode("Thing 5", 2.1)) | |
episodes.append(Episode("Thing 6", 9.2)) | |
average_rating = np.mean(map(lambda episode: episode.rating, episodes)) | |
closest_to_avg = reduce(lambda new, episode: episode if abs(average_rating - episode.rating) < abs(average_rating - new.rating) else new, episodes, Episode("An error occurred", 0)) | |
highest_rated = reduce(lambda new, episode: episode if episode.rating > new.rating else new, episodes, Episode("An error occured", 0)) | |
lowest_rated = reduce(lambda new, episode: episode if episode.rating < new.rating else new, episodes, Episode("An error occured", 10)) | |
print "Highest Rated Episode: " + highest_rated.title + ", with rating " + str(highest_rated.rating) | |
print "Lowest Rated Episode: " + lowest_rated.title + ", with rating " + str(lowest_rated.rating) | |
print "Average Rating: " + str(average_rating) | |
print "The episode closest to the mean rating is " + closest_to_avg.title + ", with rating " + str(closest_to_avg.rating) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment