Skip to content

Instantly share code, notes, and snippets.

@plallin
Created March 14, 2017 21:57
Show Gist options
  • Save plallin/165d085837e0cf46a223666d0b984f5b to your computer and use it in GitHub Desktop.
Save plallin/165d085837e0cf46a223666d0b984f5b to your computer and use it in GitHub Desktop.
file = open("recommendations.txt")
recommendation = {}
for line in file:
# print(line)
if line == "":
pass
else:
if line in recommendation:
recommendation[line] += 1
else:
recommendation[line] = 0
import operator
sorted_recommendation = sorted(recommendation.items(), key=operator.itemgetter(1), reverse=True)
with open("sorted_recommendations_asx.txt", "a") as out:
for elem in sorted_recommendation:
out.write("{} ({} points)\n".format(elem[0].strip(), elem[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment