-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.py
More file actions
22 lines (20 loc) · 761 Bytes
/
Copy pathprocess.py
File metadata and controls
22 lines (20 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
''' This python code takes dictionary.txt from the current directory and generates
anadict.txt to be saved in the same directory. It considers words of length 2-8
and ignores letters that have apostrophise or other special characters'''
f = open('dictionary.txt')
d = {}
lets = set('abcdefghijklmnopqrstuvwxyz\n') #ignore special characters
for word in f:
if len(set(word) - lets) == 0 and len(word) > 2 and len(word) < 9: #set word length
word = word.strip()
key = ''.join(sorted(word))
if key in d:
d[key].append(word)
else:
d[key] = [word]
f.close()
anadict = [' '.join([key]+value) for key, value in d.iteritems()]
anadict.sort()
f = open('anadict.txt','w') #save anadict.txt
f.write('\n'.join(anadict))
f.close()