Created
July 4, 2017 01:52
-
-
Save YellowSharkMT/1b22f8d665bffbe98e38a2e371dfd2c6 to your computer and use it in GitHub Desktop.
Calculating Favorite Weezer songs from a Reddit thread.
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
from collections import Counter | |
""" | |
One-song per line, separate entries with a line containing only an equals sign | |
""" | |
fn = '------.txt' | |
SONGS = [ | |
'my name is jonas', | |
'holiday', | |
'say it aint so', | |
'only in dreams', | |
'the world has turned and left me here', | |
'in the garage', | |
'surf wax america', | |
'no one else', | |
'buddy holly', | |
'undone - the sweater song', | |
] | |
SONG_SCORES = dict() | |
with open(fn, 'r') as f: | |
entries = [] | |
entry = [] | |
for line in f.readlines(): | |
if line.strip() == '=': | |
entries.append(entry) | |
entry = [] | |
continue | |
entry.append(line.strip()) | |
for entry in entries: | |
for song in entry: | |
try: | |
assert song in SONGS | |
except AssertionError as e: | |
print('Song mis-match: ' + song) | |
number_one_choices = [e[0] for e in entries] | |
top_3 = Counter(number_one_choices).most_common(3) | |
print('###Most-Voted for #1:') | |
print('') | |
print('Song|Votes') | |
print('---|---') | |
for song in top_3: | |
print('{}|{}'.format(song[0], song[1])) | |
for entry in entries: | |
for index, song in enumerate(entry): | |
score = len(SONGS) - index | |
SONG_SCORES[song] = SONG_SCORES.get(song, 0) + score | |
print('') | |
print('###Cumulative/Aggregate Score:') | |
print('') | |
print('Song|Score') | |
print('---|---') | |
for song, score in SONG_SCORES.items(): | |
print('{}|{}'.format(song, score)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment