From 91aa6bf76534b01c4730bde96e8fe4132d5239c0 Mon Sep 17 00:00:00 2001 From: Annie Wei Date: Wed, 6 Nov 2013 19:33:47 -0500 Subject: [PATCH 1/4] finished hello world example --- 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 1adf74811fb1788a903a4f80a9492ad459167a45 Mon Sep 17 00:00:00 2001 From: Annie Wei Date: Wed, 6 Nov 2013 19:34:00 -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 c16ae497d16b3fcac180eef1ce9b1020d5645a76 Mon Sep 17 00:00:00 2001 From: Annie Wei Date: Wed, 6 Nov 2013 19:57:19 -0500 Subject: [PATCH 3/4] finished spell checker --- exercises-spellchecker/dictionary.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/exercises-spellchecker/dictionary.py b/exercises-spellchecker/dictionary.py index e71878a..3863124 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 + lines = set([line.strip() for line in open(dictionary_name)]) + return lines def check(dictionary, word): """ Returns True if `word` is in the English `dictionary`. """ - pass + if word in dictionary: + return True + else: + return False 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=set([]) From e2e0b78526d844149848c4a16169fbf8cb092f92 Mon Sep 17 00:00:00 2001 From: Annie Wei Date: Wed, 6 Nov 2013 20:52:07 -0500 Subject: [PATCH 4/4] done --- exercises-more/exercises.py | 58 +++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index 3420fff..3ac0e7f 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -2,62 +2,88 @@ # 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 + for elt in lst: + sum += elt + 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 + seen = set([]) + for elt in lst: + seen.add(elt) + return len(seen) # 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 [] + return lst[::-1] # 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 [] + return sorted(lst, key=lambda num : -1 * num) # 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 + outstr = '' + for character in s: + if not(character.lower() in ['a','e','i','o','u']): + outstr += character + return outstr # 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 not lst: + return None + else: + newlst = sorted(lst, key=lambda word : len(word)) + return newlst[-1] # 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 {} + dict = {} + for word in lst: + if word in dict: + dict[word]=dict[word]+1 + else: + dict[word]=1 + return dict # 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 not lst: + return None + else: + dict = word_frequency(lst) + keys = dict.keys() + sortedkeys = sorted(keys, key=lambda word : dict[word]) + return (sortedkeys[-1], dict[sortedkeys[-1]]) # PROB 11 # Compares the two lists and finds all the positions that are mismatched in the list. @@ -65,10 +91,18 @@ 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 [] + mismatches = [] + for pos in range(len(lst1)): + if (lst1[pos]!=lst2[pos]): + mismatches.append(pos) + return mismatches # 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 [] + returnme = [] + for word in word_list: + if not(word in vocab_list): + returnme.append(word) + return returnme