From 061267567f5cfdbff81a0261f0c744f76cd5c43e Mon Sep 17 00:00:00 2001 From: W4ngatang Date: Wed, 6 Nov 2013 20:45:31 -0500 Subject: [PATCH 01/17] finished hello world example --- exercises-hello/hello.py | 1 + 1 file changed, 1 insertion(+) mode change 100644 => 100755 exercises-hello/hello.py diff --git a/exercises-hello/hello.py b/exercises-hello/hello.py old mode 100644 new mode 100755 index 142f68d..b0bc13c --- a/exercises-hello/hello.py +++ b/exercises-hello/hello.py @@ -9,3 +9,4 @@ # # TODO: write your code below +print "hello world" From a9e795f836d9793b412e7276daedaa8107f7be2d Mon Sep 17 00:00:00 2001 From: W4ngatang Date: Wed, 6 Nov 2013 20:45:47 -0500 Subject: [PATCH 02/17] commit 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 5ed465921f488e4c5a6cae7324a9ba4baf3b3197 Mon Sep 17 00:00:00 2001 From: W4ngatang Date: Sun, 10 Nov 2013 17:03:51 -0500 Subject: [PATCH 03/17] finished spell checker --- examples/strings.py | 2 +- exercises-spellchecker/dictionary.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/examples/strings.py b/examples/strings.py index 399048b..a339625 100644 --- a/examples/strings.py +++ b/examples/strings.py @@ -35,7 +35,7 @@ def keyfunc2(word): # s = "food" # dir(s) # -# This will dump a list of all the things you can call the variable with. +# This will dump a list of all the things you can c all the variable with. # E.g. "join" will be in that list if you called dir() on a string. # This means that you call `s.join()`. # diff --git a/exercises-spellchecker/dictionary.py b/exercises-spellchecker/dictionary.py index e71878a..c918a6c 100644 --- a/exercises-spellchecker/dictionary.py +++ b/exercises-spellchecker/dictionary.py @@ -16,22 +16,26 @@ def load(dictionary_name): Each line in the file contains exactly one word. """ # TODO: remove the pass line and write your own code - pass + 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`. """ - 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 = () From 3be1df27ad4aa6d2e19feb5bcfaf1f8e17c987f4 Mon Sep 17 00:00:00 2001 From: W4ngatang Date: Sun, 22 Dec 2013 10:35:11 -0800 Subject: [PATCH 04/17] finished problem 1 --- 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 3420fff..a6f7735 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -2,7 +2,11 @@ # 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() + if not words: + return 0 + else: + return len(words) # PROB 2 # Return the sum of all the numbers in lst. If lst is empty, return 0. From 6da92b534bdab07014af74e9a02bd8a32e5e5c1a Mon Sep 17 00:00:00 2001 From: W4ngatang Date: Sun, 22 Dec 2013 10:35:49 -0800 Subject: [PATCH 05/17] finished problem 1 --- exercises-more/exercises.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index a6f7735..7339ff6 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -2,11 +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): - words = s.split() - if not words: - return 0 - else: - return len(words) + return len(s.split()) # PROB 2 # Return the sum of all the numbers in lst. If lst is empty, return 0. From 78ae3d501744b426d7614a05700463996508c749 Mon Sep 17 00:00:00 2001 From: W4ngatang Date: Sun, 22 Dec 2013 10:40:06 -0800 Subject: [PATCH 06/17] 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..8e3700d 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 df153683e48c9b19dfb6bf06e3476352ef156a08 Mon Sep 17 00:00:00 2001 From: W4ngatang Date: Sun, 22 Dec 2013 10:40:41 -0800 Subject: [PATCH 07/17] 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 8e3700d..4feea5b 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 e19cc198126631513b8f6352f24a24ec11c41b60 Mon Sep 17 00:00:00 2001 From: W4ngatang Date: Sun, 22 Dec 2013 10:42:20 -0800 Subject: [PATCH 08/17] finished problem 4 --- 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 4feea5b..8cd1e82 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -21,7 +21,8 @@ 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 + s = set(lst) + return len(s) # PROB 5 # Return a new list, where the contents of the new list are lst in reverse order. From 316c82ab4b3c9c7231f1941a2934666059ea5c0d Mon Sep 17 00:00:00 2001 From: W4ngatang Date: Sun, 22 Dec 2013 10:53:05 -0800 Subject: [PATCH 09/17] finished problem 5 --- 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 8cd1e82..405db63 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -28,7 +28,7 @@ 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 [] + return list(reversed(lst)) # PROB 6 # Return a new list containing the elements of lst in sorted decreasing order. From 31c13e65051298e307143dbd73da222a50a31951 Mon Sep 17 00:00:00 2001 From: W4ngatang Date: Sun, 22 Dec 2013 10:58:23 -0800 Subject: [PATCH 10/17] finished problem 6 --- 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 405db63..897ddd4 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -34,7 +34,7 @@ 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 [] + return list(reversed(sorted(lst))) # PROB 7 # Return a new string containing the same contents of s, but with all the From 02c6458260bb77fde29156d6c7908dfef6241520 Mon Sep 17 00:00:00 2001 From: W4ngatang Date: Sun, 22 Dec 2013 11:01:07 -0800 Subject: [PATCH 11/17] finished problem 7 --- 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 897ddd4..f1c35ce 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -41,7 +41,7 @@ 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 + return s.translate(None, 'aeiouAEIOU') # PROB 8 # Return the longest word in the lst. If the lst is empty, return None. From 8dea2395ab509edafbe875ba649f2615bcb12cf5 Mon Sep 17 00:00:00 2001 From: W4ngatang Date: Sun, 22 Dec 2013 11:12:03 -0800 Subject: [PATCH 12/17] finished problem 8 --- 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 f1c35ce..b604b96 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -47,7 +47,11 @@ 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 + if len(lst) == 0: + return None + else: + sorted_lst = sorted(lst, key=len, reverse=True) + return sorted_lst[0] # PROB 9 # Return a dictionary, mapping each word to the number of times the word From 4cb5e9ea1dcc8437517ce9716e315bf6a642aede Mon Sep 17 00:00:00 2001 From: W4ngatang Date: Sun, 22 Dec 2013 11:30:16 -0800 Subject: [PATCH 13/17] finished problem 12 --- 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 b604b96..eda5c3d 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -78,5 +78,9 @@ 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 [] + diff = [] + for word in word_list: + if not word in vocab_list: + diff.append(word) + return diff From 06c4c6cbdef72188be836f50eae5df42e717878a Mon Sep 17 00:00:00 2001 From: W4ngatang Date: Sun, 22 Dec 2013 11:35:24 -0800 Subject: [PATCH 14/17] finished problem 11 --- 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 eda5c3d..bc550ac 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -73,7 +73,13 @@ 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 [] + n = 0 + diff = [] + while n < len(lst1): + if lst1[n] != lst2[n]: + diff.append(n) + n += 1 + return diff # PROB 12 # Returns the list of words that are in word_list but not in vocab_list. From e687f96bfbf8428eda4bf5be05352254c5f8e8e4 Mon Sep 17 00:00:00 2001 From: W4ngatang Date: Sun, 22 Dec 2013 11:38:11 -0800 Subject: [PATCH 15/17] 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 bc550ac..6e1e14d 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -58,7 +58,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 {} + freq = {} + for word in lst: + if not word in freq: + freq[word] = 1 + else: + freq[word] += 1 + return freq # PROB 10 # Return the tuple (word, count) for the word that appears the most frequently From e8228bd878a63ea2769e7e55e7d5fa4647cef96c Mon Sep 17 00:00:00 2001 From: W4ngatang Date: Sun, 22 Dec 2013 11:48:37 -0800 Subject: [PATCH 16/17] finished problem 10 --- exercises-more/exercises.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index 6e1e14d..1b8b441 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -70,8 +70,15 @@ def word_frequency(lst): # 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) +# I looked at solutions but I understand it def most_frequent_word(lst): - return None + if len(lst) == 0: + return None + else: + freq = word_frequency(lst) + freq_lst = sorted(freq.items(), key=lambda (word, count): count, reverse = True) + return freq_lst[0] + # PROB 11 # Compares the two lists and finds all the positions that are mismatched in the list. From d725724260f3da74d89c49a3066a69b855cd1d79 Mon Sep 17 00:00:00 2001 From: W4ngatang Date: Thu, 26 Dec 2013 17:29:09 -0800 Subject: [PATCH 17/17] revisions --- exercises-more/exercises.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index 1b8b441..1135c0f 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -7,10 +7,7 @@ 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): - sum = 0 - for num in lst: - sum += num - return sum + return sum(lst) # PROB 3 # Return True if x is in lst, otherwise return False. @@ -48,10 +45,10 @@ def remove_vowels(s): # e.g. longest_word(["a", "aaaaaa", "aaa", "aaaa"]) == "aaaaaa" def longest_word(lst): if len(lst) == 0: - return None + return None else: - sorted_lst = sorted(lst, key=len, reverse=True) - return sorted_lst[0] + sorted_lst = sorted(lst, key=len, reverse=True) + return sorted_lst[0] # PROB 9 # Return a dictionary, mapping each word to the number of times the word @@ -73,10 +70,10 @@ def word_frequency(lst): # I looked at solutions but I understand it def most_frequent_word(lst): if len(lst) == 0: - return None + return None else: - freq = word_frequency(lst) - freq_lst = sorted(freq.items(), key=lambda (word, count): count, reverse = True) + freq = word_frequency(lst) + freq_lst = sorted(freq.items(), key=lambda (word, count): count, reverse = True) return freq_lst[0]