Skip to content

Instantly share code, notes, and snippets.

@abdullahalbyati
Created July 17, 2018 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdullahalbyati/3cfb19b5a640962c7ff2855a5b42f23a to your computer and use it in GitHub Desktop.
Save abdullahalbyati/3cfb19b5a640962c7ff2855a5b42f23a to your computer and use it in GitHub Desktop.
from collections import Counter
import operator
input_file = open("./data/follows.txt", 'r')
wordcount = Counter(input_file.read().split())
input_file.close()
most_popular_alien = max(wordcount.items(), key=operator.itemgetter(1))
print ("Task 1: Who are the most popular users?\n")
print ("-----------------------Answer--------------------------\n\n")
print ("Aline with the user name :- " + most_popular_alien[0] + " with total numbers of followers " + str(most_popular_alien[1] - 1))
result = [v[0] for v in sorted(wordcount.items(), key=lambda kv: (-kv[1], kv[0]))]
for entry in result:
print(entry)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment