From 9c75caf0c5668425c0ea11e69b1e99037aadb65d Mon Sep 17 00:00:00 2001 From: He Li Date: Wed, 6 Nov 2013 19:29:52 -0500 Subject: [PATCH 01/10] hello world made --- exercises-hello/hello.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises-hello/hello.py b/exercises-hello/hello.py index 142f68d..9636f59 100644 --- a/exercises-hello/hello.py +++ b/exercises-hello/hello.py @@ -8,4 +8,4 @@ # Run ./test.sh to make sure your program matches our expected output. # # TODO: write your code below - +print "hello world" From e417b8da6a341a065116e6b98bd87b88b4fd75ef Mon Sep 17 00:00:00 2001 From: He Li Date: Wed, 6 Nov 2013 19:31:17 -0500 Subject: [PATCH 02/10] added script.py --- 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 1ac81187563246a5a1e94ffdacf2d62f27164e33 Mon Sep 17 00:00:00 2001 From: He Li Date: Wed, 6 Nov 2013 20:07:05 -0500 Subject: [PATCH 03/10] spellchecker done --- 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..8f6aa66 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 + f = open(dictionary_name, "r") + words = set() + for line in f: + line_stripped = line.strip() + words.add(line_stripped) + f.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 1c5e9fae3a46306b994ea91d6f5b8b9d89400502 Mon Sep 17 00:00:00 2001 From: He Li Date: Wed, 6 Nov 2013 20:18:55 -0500 Subject: [PATCH 04/10] finished problems 1 and 2 --- exercises-more/exercises.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index 3420fff..8a6987e 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -2,12 +2,15 @@ # 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) # 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 sum(lst) + else: + return 0 # PROB 3 # Return True if x is in lst, otherwise return False. From 73e83094c367541eec6c826468292f1df623b393 Mon Sep 17 00:00:00 2001 From: He Li Date: Wed, 6 Nov 2013 20:20:37 -0500 Subject: [PATCH 05/10] 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 8a6987e..f7aa813 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 ba53e0b17eefa69bb94b9d8f18ce14a4e3f6a2f0 Mon Sep 17 00:00:00 2001 From: He Li Date: Wed, 6 Nov 2013 20:23:50 -0500 Subject: [PATCH 06/10] 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 f7aa813..9f5322f 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 9ee8f28c85f6e5ab41bd070e932d36b187666fe3 Mon Sep 17 00:00:00 2001 From: He Li Date: Wed, 6 Nov 2013 20:25:27 -0500 Subject: [PATCH 07/10] 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 9f5322f..6e15157 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -27,7 +27,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 reversed(lst) # PROB 6 # Return a new list containing the elements of lst in sorted decreasing order. From 99ed3513bc4ce985c2b323333fa5132e1506a38d Mon Sep 17 00:00:00 2001 From: He Li Date: Wed, 6 Nov 2013 21:46:58 -0500 Subject: [PATCH 08/10] finished problem 6 and 7 --- exercises-more/exercises.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index 6e15157..f5b8d0c 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -33,14 +33,17 @@ 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 reversed(sorted(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): - return s + for letter in s: + if letter in ['a','e','i','o','u']: + s = s.replace(letter, '') + return s # PROB 8 # Return the longest word in the lst. If the lst is empty, return None. From 31ba0e63a0e714cccc2675df5dbc5b929e763426 Mon Sep 17 00:00:00 2001 From: He Li Date: Wed, 6 Nov 2013 21:51:07 -0500 Subject: [PATCH 09/10] finished problem 7 and 8 --- exercises-more/exercises.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index f5b8d0c..2dc82da 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -40,16 +40,19 @@ 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): - for letter in s: - if letter in ['a','e','i','o','u']: - s = s.replace(letter, '') - return s + for letter in s: + if letter in ['a','e','i','o','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 max(lst, key=len) + else: + return None # PROB 9 # Return a dictionary, mapping each word to the number of times the word From 64a6efbd0d32003102d818d35e30fe4be5a9a017 Mon Sep 17 00:00:00 2001 From: He Li Date: Thu, 7 Nov 2013 01:24:57 -0500 Subject: [PATCH 10/10] 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 2dc82da..37540ef 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -59,7 +59,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 {} + new_dict = {} + for word in lst: + if word in new_dict: + new_dict[word] += 1 + else: + new_dict[word] = 1 + # PROB 10 # Return the tuple (word, count) for the word that appears the most frequently