forked from fhcwcsy/python_practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgutemberg.py
More file actions
56 lines (48 loc) · 1.24 KB
/
Copy pathgutemberg.py
File metadata and controls
56 lines (48 loc) · 1.24 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
start = False
import string
def get_wordlist( filename ):
global start
fin = open( filename )
wordlist = dict()
word = ""
nope = string.punctuation + string.whitespace + "1234567890"
for line in fin:
for char in line:
if word == "preface":
start = True
if not ( char in nope ):
word += char.lower()
elif not len(word) == 0:
if start:
wordlist[ word ] = wordlist.get( word , 0 ) + 1
word = ""
return wordlist
def get_dict( filename ):
fin = open( filename )
wordlist = dict()
for line in fin:
word = line.strip()
wordlist[ word ] = None
return wordlist
if __name__ == "__main__":
book_dict = get_wordlist( "../../Downloads/book.txt" )
# print( "length: ", len(book_dict) )
# FREQ SORT
# freq_list = []
# for word in book_dict:
# if not book_dict[ word ] in freq_list:
# freq_list.append( book_dict[ word ] )
# count = 0
# for freq in reversed( sorted( freq_list ) ) :
# for word in book_dict:
# if book_dict[ word ] == freq:
# print( word, book_dict[ word ] )
# count += 1
# if count > 30 :
# exit()
dictionary = get_dict( "../../Downloads/words.txt" )
# for i in range( 50 ):
# print( wordlist[i] )
for word in book_dict:
if not ( word in dictionary ):
print( word )