From 129cfa5e1c656a1b6755114411110c9c317f619c Mon Sep 17 00:00:00 2001 From: Maggie Vo Date: Wed, 6 Nov 2013 19:31:58 -0500 Subject: [PATCH 1/4] finished hello world example --- exercises-hello/hello.py | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises-hello/hello.py b/exercises-hello/hello.py index 142f68d..b0bc13c 100644 --- a/exercises-hello/hello.py +++ b/exercises-hello/hello.py @@ -9,3 +9,4 @@ # # TODO: write your code below +print "hello world" From 30fcf60b4794987db6f8111d23661040355f54c9 Mon Sep 17 00:00:00 2001 From: Maggie Vo Date: Wed, 6 Nov 2013 19:31:58 -0500 Subject: [PATCH 2/4] created python script --- exercises-hello/script.py | 2 ++ 1 file changed, 2 insertions(+) create mode 100755 exercises-hello/script.py diff --git a/exercises-hello/script.py b/exercises-hello/script.py new file mode 100755 index 0000000..f88d80d --- /dev/null +++ b/exercises-hello/script.py @@ -0,0 +1,2 @@ +#!/usr/bin/env python +print "this is a python script!" From 791e4f28be1a789d6bd5f68ebbab44f7fe7db422 Mon Sep 17 00:00:00 2001 From: Maggie Vo Date: Wed, 6 Nov 2013 20:08:05 -0500 Subject: [PATCH 3/4] finished spell checker --- exercises-spellchecker/dictionary.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/exercises-spellchecker/dictionary.py b/exercises-spellchecker/dictionary.py index e71878a..1507166 100644 --- a/exercises-spellchecker/dictionary.py +++ b/exercises-spellchecker/dictionary.py @@ -15,23 +15,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() + words_file = open(dictionary_name, "rb") + for word in words_file: + word = word.strip() + words.add(word) + words_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(dictionary) def unload(dictionary): """ Removes everything from the English `dictionary`. """ - pass + dictionary.clear() From 9dc17b9e95e7d4af26196225fb72edfcb7d9c1dc Mon Sep 17 00:00:00 2001 From: Maggie Vo Date: Wed, 13 Nov 2013 00:28:10 -0500 Subject: [PATCH 4/4] finished everything but finding the mismatch --- exercises-more/exercises.py | 44 ++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index 3420fff..3773496 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -2,62 +2,86 @@ # 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 + words = s.split() + return len(words) # PROB 2 # Return the sum of all the numbers in lst. If lst is empty, return 0. def sum_list(lst): - return 0 + if len(lst) == 0: + return len(lst) + else: + return sum(lst) # 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 + newLst = list(set(lst)) + return len(newLst) # 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 [] + lst.reverse() + return lst # 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 [] + lst.sort() + lst.reverse() + return lst # PROB 7 # Return a new string containing the same contents of s, but with all the # vowels (upper and lower case) removed. Vowels do not include 'y' # e.g. remove_vowels("abcdeABCDE") == "bcdBCD" def remove_vowels(s): + for letter in s: + if letter in ['a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U']: + s = s.replace(letter, '') return s # PROB 8 # Return the longest word in the lst. If the lst is empty, return None. # e.g. longest_word(["a", "aaaaaa", "aaa", "aaaa"]) == "aaaaaa" def longest_word(lst): - return None + if len(lst) == 0: + return None + else: + word = max(set(lst), key=len) + return word # PROB 9 # Return a dictionary, mapping each word to the number of times the word # appears in lst. # e.g. word_frequency(["a", "a", "aaa", "b", "b", "b"]) == {"a": 2, "aaa": 1, "b": 3} def word_frequency(lst): - return {} + words = list(set(lst)) + d = {} + for word in words: + freq = lst.count(word) + d[word] = freq + return d # PROB 10 # Return the tuple (word, count) for the word that appears the most frequently # in the list, and the number of times the word appears. If the list is empty, return None. # e.g. most_frequent_word(["a", "a", "aaa", "b", "b", "b"]) == ("b", 3) def most_frequent_word(lst): - return None + if len(lst) == 0: + return None + else: + word = max(set(lst), key=lst.count) + return (word, lst.count(word)) # PROB 11 # Compares the two lists and finds all the positions that are mismatched in the list. @@ -70,5 +94,5 @@ def find_mismatch(lst1, lst2): # PROB 12 # Returns the list of words that are in word_list but not in vocab_list. def spell_checker(vocab_list, word_list): - return [] + return list(set(word_list) - set(vocab_list))