Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First python scripts #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion exercises-hello/hello.py
Expand Up @@ -7,5 +7,5 @@
#
# Run ./test.sh to make sure your program matches our expected output.
#
# TODO: write your code below
print "Hello World"

3 changes: 3 additions & 0 deletions exercises-hello/script.py
@@ -0,0 +1,3 @@
#!/usr/bin/env python
print "this is a python script!"

15 changes: 11 additions & 4 deletions exercises-spellchecker/dictionary.py
Expand Up @@ -16,22 +16,29 @@ def load(dictionary_name):
Each line in the file contains exactly one word.
"""
# TODO: remove the pass line and write your own code
pass
dic = open(dictionary_name, "r")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

careful with indentation. another cool thing to use is set comprehensions:

return {word.strip() for word in open(dictionary_name, "r")}

words = set()
for line in dic:
line_stripped = line.strip()
words.add(line_stripped)
dic.close()
return words

def check(dictionary, word):
"""
Returns True if `word` is in the English `dictionary`.
"""
pass
return word in dictionary

def size(dictionary):
"""
Returns the number of words in the English `dictionary`.
"""
pass
return len(dictionary)

def unload(dictionary):
"""
Removes everything from the English `dictionary`.
"""
pass
dictionary.clear()
return True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to return anything