Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download

📚 The CoCalc Library - books, templates and other resources

Views: 96169
License: OTHER
1
"""This module contains a code example related to
2
3
Think Python, 2nd Edition
4
by Allen Downey
5
http://thinkpython2.com
6
7
Copyright 2015 Allen Downey
8
9
License: http://creativecommons.org/licenses/by/4.0/
10
"""
11
12
from __future__ import print_function, division
13
14
from analyze_book1 import process_file
15
16
17
def subtract(d1, d2):
18
"""Returns a set of all keys that appear in d1 but not d2.
19
20
d1, d2: dictionaries
21
"""
22
return set(d1) - set(d2)
23
24
25
def main():
26
hist = process_file('158-0.txt', skip_header=True)
27
words = process_file('words.txt', skip_header=False)
28
29
diff = subtract(hist, words)
30
print("The words in the book that aren't in the word list are:")
31
for word in diff:
32
print(word, end=' ')
33
34
35
if __name__ == '__main__':
36
main()
37
38
39