From 54247356a4b68049df0460e57595b1af29d8cf58 Mon Sep 17 00:00:00 2001 From: Nabib Ahmed Date: Fri, 4 Nov 2016 00:49:15 -0400 Subject: [PATCH 01/13] 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..6697b3b 100644 --- a/exercises-hello/hello.py +++ b/exercises-hello/hello.py @@ -9,3 +9,4 @@ # # TODO: write your code below +print "hello world" \ No newline at end of file From 45f5986c7a136a4d460003e78764519443eacb07 Mon Sep 17 00:00:00 2001 From: Nabib Ahmed Date: Fri, 4 Nov 2016 00:49:44 -0400 Subject: [PATCH 02/13] 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..1b9f121 --- /dev/null +++ b/exercises-hello/script.py @@ -0,0 +1,2 @@ +#!/usr/bin/env python +print "this is a python script!" \ No newline at end of file From 662b942cac092c7006431fbcf86e156eabed8788 Mon Sep 17 00:00:00 2001 From: Nabib Ahmed Date: Fri, 4 Nov 2016 01:44:04 -0400 Subject: [PATCH 03/13] finished spell checker --- exercises-spellchecker/dictionary.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/exercises-spellchecker/dictionary.py b/exercises-spellchecker/dictionary.py index e71878a..fea22c3 100644 --- a/exercises-spellchecker/dictionary.py +++ b/exercises-spellchecker/dictionary.py @@ -16,22 +16,35 @@ def load(dictionary_name): Each line in the file contains exactly one word. """ # TODO: remove the pass line and write your own code - pass + + # Get an array of the file content + with open(dictionary_name) as f: + content = f.readlines() + + # Make an empty set + dictionary = set([]) + + # Cleaning each word and adding them to the set + for word in content: + dictionary.add( word.strip().strip('\n') ) + + return dictionary + 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 + return set([]) From 13480e1495012623308de4a18623c3b271f36b27 Mon Sep 17 00:00:00 2001 From: Nabib Ahmed Date: Fri, 4 Nov 2016 06:25:00 -0400 Subject: [PATCH 04/13] finished problem num_words --- 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..2549a03 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 a351307262c6b5659f82a0dc51169385e81937fd Mon Sep 17 00:00:00 2001 From: Nabib Ahmed Date: Fri, 4 Nov 2016 06:27:23 -0400 Subject: [PATCH 05/13] finished problem 2 --- 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 2549a03..d883389 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -7,8 +7,9 @@ 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 + return sum(lst) +print sum_list([]) # PROB 3 # Return True if x is in lst, otherwise return False. def appears_in_list(x, lst): From 4f2478c1675022b2e017e259a39cad74c8d01955 Mon Sep 17 00:00:00 2001 From: Nabib Ahmed Date: Fri, 4 Nov 2016 06:28:31 -0400 Subject: [PATCH 06/13] finished problem 3 --- exercises-more/exercises.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index d883389..d0aa408 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -9,11 +9,12 @@ def num_words(s): def sum_list(lst): return sum(lst) -print sum_list([]) # PROB 3 # Return True if x is in lst, otherwise return False. def appears_in_list(x, lst): - return False + return x in lst + +print appears_in_list(8, [1,2,4,6]) # PROB 4 # Return the number of unique strings in lst. From eff7e2b3130815d63d0f19a32e47eaea025e9dd3 Mon Sep 17 00:00:00 2001 From: Nabib Ahmed Date: Fri, 4 Nov 2016 06:28:37 -0400 Subject: [PATCH 07/13] finished problem 3 --- exercises-more/exercises.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index d0aa408..1b88a99 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -14,8 +14,6 @@ def sum_list(lst): def appears_in_list(x, lst): return x in lst -print appears_in_list(8, [1,2,4,6]) - # PROB 4 # Return the number of unique strings in lst. # e.g. num_unique(["a", "b", "a", "c", "a"]) == 3 From 7d2e23121aa517dc3b70ca8c96a5cd7982a0b86a Mon Sep 17 00:00:00 2001 From: Nabib Ahmed Date: Fri, 4 Nov 2016 06:38:04 -0400 Subject: [PATCH 08/13] solved problem 5-7 --- exercises-more/exercises.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index 1b88a99..20e6301 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -18,19 +18,22 @@ 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 + unique = set(lst) + return len(unique) # 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 [] + # http://stackoverflow.com/questions/3940128/how-can-i-reverse-a-list-in-python + 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 [] + # http://stackoverflow.com/questions/11750469/python-list-sort-doesnt-seem-to-work + return reverse_list( sorted(lst, key=int) ) # PROB 7 # Return a new string containing the same contents of s, but with all the From 087a1b0006f325ebc357ff561f07e42a8b0a37a5 Mon Sep 17 00:00:00 2001 From: Nabib Ahmed Date: Fri, 4 Nov 2016 06:52:21 -0400 Subject: [PATCH 09/13] solved problem 4,8-9 --- exercises-more/exercises.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index 20e6301..b5d268e 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -40,13 +40,21 @@ 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): + # http://stackoverflow.com/questions/3939361/remove-specific-characters-from-a-string-in-python + vowels = "aeouiAEOUI" + for char in vowels: + s = s.replace(char, "") 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 + word = None + for item in lst: + if word == None or len(item) > len(word): + word = item + return word # PROB 9 # Return a dictionary, mapping each word to the number of times the word From 3662347a3ffe5af8a9d6ca06d74836a91a9a3f86 Mon Sep 17 00:00:00 2001 From: Nabib Ahmed Date: Fri, 4 Nov 2016 07:02:31 -0400 Subject: [PATCH 10/13] solved problem 9 --- exercises-more/exercises.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index b5d268e..e5cf5cd 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -61,7 +61,15 @@ 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 {} + # http://stackoverflow.com/questions/2161752/how-to-count-the-frequency-of-the-elements-in-a-list + word_freq = {} + unique = set(lst) + for element in unique: + word_freq[element] = lst.count(element) + return word_freq + + + # PROB 10 # Return the tuple (word, count) for the word that appears the most frequently From de55ef49231d9c2f7093539734356d3b1613a381 Mon Sep 17 00:00:00 2001 From: Nabib Ahmed Date: Fri, 4 Nov 2016 07:06:54 -0400 Subject: [PATCH 11/13] solved problem 10 --- exercises-more/exercises.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index e5cf5cd..a3f3aed 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -68,15 +68,17 @@ def word_frequency(lst): word_freq[element] = lst.count(element) return word_freq - - - # 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 + word = None + unique = set(lst) + for element in unique: + if word == None or lst.count(element) > lst.count(word[0]): + word = (element, lst.count(element)) + return word # PROB 11 # Compares the two lists and finds all the positions that are mismatched in the list. From 5ebc34c2c86539cb1f5992bd448541a5a1cadd58 Mon Sep 17 00:00:00 2001 From: Nabib Ahmed Date: Fri, 4 Nov 2016 07:10:08 -0400 Subject: [PATCH 12/13] solved problem 11 --- exercises-more/exercises.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index a3f3aed..68aa830 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -86,8 +86,12 @@ 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 i in range(len(lst1)): + if lst1[i] != lst2[i]: + mismatches.append(i) + return mismatches +print find_mismatch(["a", "b", "c", "d", "e"], ["f", "b", "c", "g", "e"]) # PROB 12 # Returns the list of words that are in word_list but not in vocab_list. def spell_checker(vocab_list, word_list): From 74b7a6963f8628a0795b311d20b958a5f97bdb13 Mon Sep 17 00:00:00 2001 From: Nabib Ahmed Date: Fri, 4 Nov 2016 07:12:23 -0400 Subject: [PATCH 13/13] solved problem 12 --- exercises-more/exercises.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/exercises-more/exercises.py b/exercises-more/exercises.py index 68aa830..7d81d40 100644 --- a/exercises-more/exercises.py +++ b/exercises-more/exercises.py @@ -91,9 +91,13 @@ def find_mismatch(lst1, lst2): if lst1[i] != lst2[i]: mismatches.append(i) return mismatches -print find_mismatch(["a", "b", "c", "d", "e"], ["f", "b", "c", "g", "e"]) + # 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 [] + words = [] + for item in word_list: + if (item in vocab_list) == False: + words.append(item) + return words