File tree 2 files changed +235914
-0
lines changed
2 files changed +235914
-0
lines changed Original file line number Diff line number Diff line change
1
+ import collections , pprint , time , os
2
+
3
+ start_time = time .time ()
4
+ print ('creating word list...' )
5
+ path = os .path .split (os .path .realpath (__file__ ))
6
+ word_list = sorted (list (set ([word .strip ().lower () for word in open (path [0 ] + '/words' )])))
7
+
8
+ def signature (word ):
9
+ return '' .join (sorted (word ))
10
+
11
+ word_bysig = collections .defaultdict (list )
12
+ for word in word_list :
13
+ word_bysig [signature (word )].append (word )
14
+
15
+ def anagram (myword ):
16
+ return word_bysig [signature (myword )]
17
+
18
+ print ('finding anagrams...' )
19
+ all_anagrams = {word : anagram (word )
20
+ for word in word_list if len (anagram (word )) > 1 }
21
+
22
+ print ('writing anagrams to file...' )
23
+ with open ('anagrams.txt' , 'w' ) as file :
24
+ file .write ('all_anagrams = ' )
25
+ file .write (pprint .pformat (all_anagrams ))
26
+
27
+ total_time = round (time .time () - start_time , 2 )
28
+ print ('Done [' , total_time , 'seconds ]' )
You can’t perform that action at this time.
0 commit comments