-
Notifications
You must be signed in to change notification settings - Fork 1
/
1.py
39 lines (30 loc) · 988 Bytes
/
1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import sys, json, itertools
x = sys.argv[1]
dic = json.loads(sys.argv[2])
x = int(x)
school_list = []
for line in dic:
array_temp = []
for temp in line:
if "school" in temp:
array_temp.append(int(line[temp]))
school_list.append(array_temp)
recom_dict = {}
for i in school_list:
for j in i:
if(x == j):
for item in itertools.combinations(i, 2):
if x in item:
item = sorted(item)
item = tuple(item)
item = ' '.join(map(str, item))
if item in recom_dict:
recom_dict[item] += 1
else:
recom_dict[item] = 1
recom_list = sorted(recom_dict.items(), key = lambda x: (-x[1]))
final_recom = []
for i in range(0, 5):
temp = recom_list[i][0].replace(str(x), '')
final_recom.append(int(temp.replace(' ','')))
print(json.dumps(final_recom))