From 50becf78abda94859ccf75d66c7848c07d6de400 Mon Sep 17 00:00:00 2001 From: Erin Masatsugu Date: Sun, 17 Nov 2013 22:02:20 -0500 Subject: [PATCH 01/15] finished hello world example --- exercises-hello/hello.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/exercises-hello/hello.py b/exercises-hello/hello.py index 142f68d..b163e1f 100644 --- a/exercises-hello/hello.py +++ b/exercises-hello/hello.py @@ -9,3 +9,5 @@ # # TODO: write your code below + +print "hello world"; From 685e68860431c5f97ce94d0a2d348ff9c48ddf38 Mon Sep 17 00:00:00 2001 From: Erin Masatsugu Date: Sun, 17 Nov 2013 22:02:54 -0500 Subject: [PATCH 02/15] created python script --- exercises-hello/script.py | 3 +++ 1 file changed, 3 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..b5c2d1c --- /dev/null +++ b/exercises-hello/script.py @@ -0,0 +1,3 @@ +#!/usr/bin/env python +print "this is a python script!" + From ff2f6130c8fabc311b3f050adf950916175fe3cf Mon Sep 17 00:00:00 2001 From: Erin Masatsugu Date: Mon, 18 Nov 2013 00:47:31 -0500 Subject: [PATCH 03/15] finished spell checker --- exercises-spellchecker/dictionary.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/exercises-spellchecker/dictionary.py b/exercises-spellchecker/dictionary.py index e71878a..0903a05 100644 --- a/exercises-spellchecker/dictionary.py +++ b/exercises-spellchecker/dictionary.py @@ -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)) def unload(dictionary): """ Removes everything from the English `dictionary`. """ - pass + dictionary.clear(); From bf3f73c0619ec69b4e5f763b69081eca99e1a0c6 Mon Sep 17 00:00:00 2001 From: Erin Masatsugu Date: Mon, 18 Nov 2013 00:52:32 -0500 Subject: [PATCH 04/15] finished problem 1 --- exercises-more/exercises.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index 3420fff..7339ff6 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -2,7 +2,7 @@ # 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. From ddddd9a1aa6fce901ac9bdbc74c910e9d45b7f11 Mon Sep 17 00:00:00 2001 From: Erin Masatsugu Date: Mon, 18 Nov 2013 00:53:49 -0500 Subject: [PATCH 05/15] finished problem 2 --- exercises-more/exercises.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index 7339ff6..558f6c2 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -7,7 +7,10 @@ def num_words(s): # 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 + for num in lst: + sum += num + return sum # PROB 3 # Return True if x is in lst, otherwise return False. From 5e34fd2518f53745b506db7df02159b99cd0fcb7 Mon Sep 17 00:00:00 2001 From: Erin Masatsugu Date: Mon, 18 Nov 2013 00:55:04 -0500 Subject: [PATCH 06/15] finished problem 3 --- exercises-more/exercises.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index 558f6c2..3bc53dd 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -15,7 +15,7 @@ def sum_list(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. From c9c2f6d728beb34a01f539cdcc1b4c560959a4af Mon Sep 17 00:00:00 2001 From: Erin Masatsugu Date: Mon, 18 Nov 2013 00:57:47 -0500 Subject: [PATCH 07/15] finished problem 4 --- exercises-more/exercises.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index 3bc53dd..e0ce2cc 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -21,7 +21,7 @@ def appears_in_list(x, lst): # 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. From 7ae2efad236dd299335404cadceabf88dc717155 Mon Sep 17 00:00:00 2001 From: Erin Masatsugu Date: Mon, 18 Nov 2013 01:06:24 -0500 Subject: [PATCH 08/15] finished problem 5 --- exercises-more/exercises.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index e0ce2cc..f1c4da8 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -27,7 +27,11 @@ def num_unique(lst): # 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): + newlst.append(x) + return newlst; + # PROB 6 # Return a new list containing the elements of lst in sorted decreasing order. From b5dd47babe4cf2d9a3034a3db2cfa3887e4cdca5 Mon Sep 17 00:00:00 2001 From: Erin Masatsugu Date: Mon, 18 Nov 2013 01:07:58 -0500 Subject: [PATCH 09/15] finished problem 6 --- exercises-more/exercises.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index f1c4da8..b95826e 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -37,7 +37,8 @@ def reverse_list(lst): # 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) + return reverse_list(newlst) # PROB 7 # Return a new string containing the same contents of s, but with all the From 5e97fcf36f1c6bfc096fdc1afcf5ea57db28d757 Mon Sep 17 00:00:00 2001 From: Erin Masatsugu Date: Mon, 18 Nov 2013 01:16:35 -0500 Subject: [PATCH 10/15] finished problem 7 --- exercises-more/exercises.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index b95826e..bbfea62 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -45,7 +45,13 @@ def sort_reverse(lst): # vowels (upper and lower case) removed. Vowels do not include 'y' # e.g. remove_vowels("abcdeABCDE") == "bcdBCD" def remove_vowels(s): - return s + news = s; + vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'] + for letter in s: + if letter in vowels: + news = news.replace(letter, "") + return news + # PROB 8 # Return the longest word in the lst. If the lst is empty, return None. From de8a990a3c430713ee9873031fd61ef9d5cf36d4 Mon Sep 17 00:00:00 2001 From: Erin Masatsugu Date: Mon, 18 Nov 2013 01:20:39 -0500 Subject: [PATCH 11/15] finished problem 8 --- exercises-more/exercises.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index bbfea62..e39f9ea 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -57,7 +57,13 @@ def remove_vowels(s): # 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 + longest = "" + if len(lst) == 0: + return None; + for word in lst: + if len(word) > len(longest): + longest = word + return longest; # PROB 9 # Return a dictionary, mapping each word to the number of times the word From 2266084f6f29a99c3968f0dbf3efd67442320350 Mon Sep 17 00:00:00 2001 From: Erin Masatsugu Date: Mon, 18 Nov 2013 01:29:08 -0500 Subject: [PATCH 12/15] finished problem 9 --- exercises-more/exercises.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index e39f9ea..be3febc 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -70,7 +70,13 @@ def longest_word(lst): # appears in lst. # e.g. word_frequency(["a", "a", "aaa", "b", "b", "b"]) == {"a": 2, "aaa": 1, "b": 3} def word_frequency(lst): - return {} + cnt = {} + for word in lst: + if word in cnt: + cnt[word] += 1 + else: + cnt[word] = 1 + return cnt; # PROB 10 # Return the tuple (word, count) for the word that appears the most frequently From af3c172f8bef58c5168da2f18cf4e5cb2931c892 Mon Sep 17 00:00:00 2001 From: Erin Masatsugu Date: Mon, 18 Nov 2013 01:41:44 -0500 Subject: [PATCH 13/15] finished problem 10 --- exercises-more/exercises.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index be3febc..d6843e9 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -83,7 +83,12 @@ def word_frequency(lst): # 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 + freqs = word_frequency(lst) + sortedfreqs = sorted(freqs.items(), key=lambda (word,count): count, reverse=True) + return sortedfreqs[0] + # PROB 11 # Compares the two lists and finds all the positions that are mismatched in the list. From 7e68aaf9a2640150214da295a20fc443295144ca Mon Sep 17 00:00:00 2001 From: Erin Masatsugu Date: Mon, 18 Nov 2013 01:45:04 -0500 Subject: [PATCH 14/15] finished problem 11 --- exercises-more/exercises.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index d6843e9..853d8e0 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -96,7 +96,11 @@ def most_frequent_word(lst): # mismatched positions in the list. # e.g. find_mismatch(["a", "b", "c", "d", "e"], ["f", "b", "c", "g", "e"]) == [0, 3] def find_mismatch(lst1, lst2): - return [] + mismatch = [] + for i in range(len(lst1)): + if lst1[i] != lst2[i]: + mismatch.append(i) + return mismatch # PROB 12 # Returns the list of words that are in word_list but not in vocab_list. From 3329366e75e06c25dccf48bff38548b21c94a912 Mon Sep 17 00:00:00 2001 From: Erin Masatsugu Date: Mon, 18 Nov 2013 01:47:47 -0500 Subject: [PATCH 15/15] finished problem 12 --- exercises-more/exercises.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index 853d8e0..7dd467b 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -105,5 +105,10 @@ 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 [] + #vocab = set(vocab_list) + misspelled = set() + for word in word_list: + if word not in vocab_list: + misspelled.add(word) + return misspelled