Skip to content

Instantly share code, notes, and snippets.

@abdullahalbyati
Created July 17, 2018 19:02
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/948cfffdaa29af17955f1b491a21ee73 to your computer and use it in GitHub Desktop.
Save abdullahalbyati/948cfffdaa29af17955f1b491a21ee73 to your computer and use it in GitHub Desktop.
import re
from collections import Counter
import operator
import sys
input_file = open("./data/stream.txt", 'r')
list=[]
for line in input_file:
if re.findall(" RT ",line):
q=line.split()[0]
list.append(line.split()[0])
wordcount=Counter(list)
#why 3930 --Uncomment the line bellow and make comment out other lines after that for answer
# or search for "ZyyXOazKeX2Bt RT" for heighest number of retweets by this user
#print(len(wordcount))
test=int(input("Please Enter Number Bellow 3930"))
while test > 3930:
print("Please input less then 3930")
test=int(input(""))
temp=0
result = [(v[0],v[1]) for v in sorted(wordcount.items(), key=lambda kv: (-kv[1], kv[0]))]
for entry in range(0,test):
if result[entry][1] == temp:
sys.stdout.write(" " + result[entry][0])
else:
sys.stdout.write("\n" + str(result[entry][1]) + " " + result[entry][0])
temp=result[entry][1]
for entry in range(test,3930):
if result[entry][1] == temp:
sys.stdout.write(" " + result[entry][0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment