forked from kennyyu/bootcamp-python
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathdictionary.py
More file actions
41 lines (35 loc) · 1.03 KB
/
dictionary.py
File metadata and controls
41 lines (35 loc) · 1.03 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
"""
We represent an English dictionary by using a python set
(don't confuse our English definition of dictionary
with a python dictionary here--anytime you see the word
"dictionary", we mean English dictionary).
"""
def load(dictionary_name):
"""
Opens the file called `dictionary_name` and returns
the set of words in that file.
Hint: call the strip() method on a word to trim surrounding
whitespace and newlines.
Each line in the file contains exactly one word.
"""
# TODO: remove the pass line and write your own code
s = set()
words = open(dictionary_name, "rb")
for word in words:
s.add(word.strip())
return s
def check(dictionary, word):
"""
Returns True if `word` is in the English `dictionary`.
"""
return word in dictionary
def size(dictionary):
"""
Returns the number of words in the English `dictionary`.
"""
return len(dictionary)
def unload(dictionary):
"""
Removes everything from the English `dictionary`.
"""
dictionary = ()