Skip to content

Instantly share code, notes, and snippets.

@abdullahalbyati
Created July 17, 2018 19:27
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/41e48cf7c2d909d4166ee52e4b27c7b7 to your computer and use it in GitHub Desktop.
Save abdullahalbyati/41e48cf7c2d909d4166ee52e4b27c7b7 to your computer and use it in GitHub Desktop.
import re
from collections import Counter
import operator
import sys
import json
import time
start_time = time.clock()
followers_map={}
input_file = open("./data/follows.txt", "r")
for line in input_file:
followers_map[line.split()[0]] = [0,0,0]
input_file.close()
input_file = open("./data/follows.txt", 'r')
for line in input_file:
for word in line.split():
if word != line.split()[0]:
followers_map[word].append(line.split()[0])
input_file.close()
print (time.clock() - start_time, "seconds")
#some_list[-1]
input_file = open("./data/stream.txt", "r")
for line in input_file:
followers_map[line.split()[0]][0] = followers_map[line.split()[0]][0] + len([ t for t in line.split() if t.startswith('@') and t not in followers_map[line.split()[0]]]) + len(followers_map[line.split()[0]]) - 3
followers_map[line.split()[0]][1] = followers_map[line.split()[0]][1] + 1
if followers_map[line.split()[0]][1] != 0:
followers_map[line.split()[0]][2] = round(followers_map[line.split()[0]][0] / followers_map[line.split()[0]][1], 1)
input_file.close()
print (time.clock() - start_time, "seconds")
# file = open("./data/map.txt", 'w')
# file.write(json.dumps(followers_map))
# file.close()
# print (time.clock() - start_time, "seconds")
# sys.exit("some message")
result=[]
for entry in followers_map:
result.append((entry, followers_map[entry][2]))
test=int(input("Please input less then 5000"))
while test > 5000:
print("Please input less then 5000")
test=int(input(""))
temp=0
result = sorted(result, key=lambda x: (-x[1] , x[0]))
for entry in range(0,test):
if result[entry][1] == temp:
sys.stdout.write(" " + result[entry][0])
# sys.stdout.write(" " + result[entry][0] +" " + str(result[entry][2]))
else:
sys.stdout.write("\n" + str(result[entry][1]) + " " + result[entry][0])
# sys.stdout.write("\n" + str(result[entry][1]) + " " + result[entry][0] +" " + str(result[entry][2]))
temp=result[entry][1]
for entry in range(test,5000):
if result[entry][1] == temp:
sys.stdout.write(" " + result[entry][0])
# sys.stdout.write(" " + result[entry][0]+" "+ str(result[entry][2]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment