Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added main function for all files

  • Loading branch information...
commit 40a24b324b6baab2b707b710692f8b7b728571d6 1 parent c7d2b6d
Zach Williams authored
6 1_2_reverse.py
View
@@ -5,7 +5,11 @@ def reverse(string):
"""Reverse a given string."""
return string[::-1]
-if __name__ == '__main__':
+
+def main():
print reverse('a')
print reverse('abcd')
print reverse('hello world')
+
+if __name__ == '__main__':
+ main()
12 1_3_duplicate_characters.py
View
@@ -7,16 +7,24 @@ def remove_duplicates(string):
def remove_with_dict(string):
- """Implement my own set function."""
+ """Implement own set function as dict keys."""
string_dict = {}
for letter in string:
string_dict[letter] = True
return string_dict.keys()
-if __name__ == '__main__':
+
+def main():
+ # Sets.
print remove_duplicates('a')
+ print remove_duplicates('abb')
print remove_duplicates('abcd')
print remove_duplicates('abcda')
+ # List of dictionay keys.
print remove_with_dict('a')
+ print remove_with_dict('abb')
print remove_with_dict('abcd')
print remove_with_dict('abcda')
+
+if __name__ == '__main__':
+ main()
10 1_4_anagrams.py
View
@@ -5,8 +5,12 @@ def anagram(first, second):
"""Decide if two strings are anagrams of one another."""
return sorted(first) == sorted(second)
-if __name__ == '__main__':
+
+def main():
print anagram('a', 'b')
- print anagram('a', 'A')
+ print anagram('a', 'aa')
print anagram('hi', 'hi')
- print anagram('hello there', 'hello there')
+ print anagram('hello there', 'there hello')
+
+if __name__ == '__main__':
+ main()
6 1_5_spaces.py
View
@@ -7,7 +7,11 @@ def replace_space(string):
"""Replace all spaces in a word with `%20`."""
return re.sub(' ', '%20', string)
-if __name__ == '__main__':
+
+def main():
print replace_space('abcd')
print replace_space('hello world')
print replace_space('another working example')
+
+if __name__ == '__main__':
+ main()
5 1_7_matrix_0.py
View
@@ -25,7 +25,7 @@ def adjust_matrix(matrix):
return matrix
-if __name__ == '__main__':
+def main():
matrix = [[1],[2],[3]]
print adjust_matrix(matrix)
@@ -38,3 +38,6 @@ def adjust_matrix(matrix):
matrix = [[1, 2, 3, 4], [1, 2, 3, 4],
[1, 2, 0, 4], [1, 2, 3, 4]]
print adjust_matrix(matrix)
+
+if __name__ == '__main__':
+ main()
20 3_2_stack_with_minimum.py
View
@@ -42,18 +42,18 @@ def min(self):
def main():
- z = Stack()
- z.push(1)
- z.push(2)
- z.push(3)
- node = z.pop()
+ stack = Stack()
+ stack.push(1)
+ stack.push(2)
+ stack.push(3)
+ node = stack.pop()
print node.minimum
- z.push(0)
- z.push(4)
- node = z.pop()
+ stack.push(0)
+ stack.push(4)
+ node = stack.pop()
print node.min()
- print z.min()
- print z
+ print stack.min()
+ print stack
if __name__ == '__main__':
main()
Please sign in to comment.
Something went wrong with that request. Please try again.