-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSorter.py
More file actions
58 lines (47 loc) · 1.04 KB
/
Sorter.py
File metadata and controls
58 lines (47 loc) · 1.04 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import json
def first(z):
return z[0]
def clean(x):
y=''
s=['.',',','-','/','}','{','"',':',';','(',')','[',']','“','«','»','°']
for i in x:
if i in s:
continue
else:
y+=i
return y
def squish(x):
s = frozenset(x)
return sorted(s)
d={}
ln=0
for x in range(1, 49):
f=open("file"+str(x)+".txt", "r")
if f.mode=='r':
contents = f.read()
contents = clean(contents)
tokens = list(map(str, contents.split(" ")))
# tokens = contents.split(" ")
ln+=1
#you used contents instead of tokens below
for word in tokens:
if word not in d:
d[word]=[]
d[word].append(1)
d[word].append([ln])
else:
d[word][0]+=1
d[word][1].append(ln)
else:
exit()
# for s in tokens:
# wordDict[s]=x
f = open("dict.json", "w+")
print('list of d')
ld=list(d)
ld.sort(key=str.lower)
count=0
# for k in ld:
# print(k,d[k][0],squish(d[k][1]))
json.dump(d, f)
# print(str(dict[y]))