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

emasatsugu python bootcamp #10

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions exercises-hello/hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
#
# TODO: write your code below


print "hello world";
3 changes: 3 additions & 0 deletions exercises-hello/script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python
print "this is a python script!"

20 changes: 14 additions & 6 deletions exercises-more/exercises.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,43 @@
# Return the number of words in the string s. Words are separated by spaces.
# e.g. num_words("abc def") == 2
def num_words(s):
return 0
return len(s.split())

# PROB 2
# Return the sum of all the numbers in lst. If lst is empty, return 0.
def sum_list(lst):
return 0
sum = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

return sum(lst)

for num in lst:
sum += num
return sum

# PROB 3
# Return True if x is in lst, otherwise return False.
def appears_in_list(x, lst):
return False
return x in lst;

# PROB 4
# Return the number of unique strings in lst.
# e.g. num_unique(["a", "b", "a", "c", "a"]) == 3
def num_unique(lst):
return 0
return len(set(lst))

# PROB 5
# Return a new list, where the contents of the new list are lst in reverse order.
# e.g. reverse_list([3, 2, 1]) == [1, 2, 3]
def reverse_list(lst):
return []
newlst = []
for x in reversed(lst):
Copy link
Collaborator

Choose a reason for hiding this comment

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

return reversed(lst)

newlst.append(x)
return newlst;


# PROB 6
# Return a new list containing the elements of lst in sorted decreasing order.
# e.g. sort_reverse([5, 7, 6, 8]) == [8, 7, 6, 5]
def sort_reverse(lst):
return []
newlst = sorted(lst)
Copy link
Collaborator

Choose a reason for hiding this comment

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

return sorted(lst, reverse=True)

return reverse_list(newlst)

# PROB 7
# Return a new string containing the same contents of s, but with all the
Expand Down
14 changes: 10 additions & 4 deletions exercises-spellchecker/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,28 @@ def load(dictionary_name):
Each line in the file contains exactly one word.
"""
# TODO: remove the pass line and write your own code
pass
words = set();
word_file = open(dictionary_name, "rb")
for word in word_file:
word = word.strip()
words.add(word)
word_file.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(list(dictionary))
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 transform dictionary into a list! you can just call len(dictionary)


def unload(dictionary):
"""
Removes everything from the English `dictionary`.
"""
pass
dictionary.clear();