From d749b9ed3362a31b889d69c5efdaaf4d5c886722 Mon Sep 17 00:00:00 2001 From: Sean Date: Fri, 25 Jun 2021 08:15:32 -0400 Subject: [PATCH 1/2] first round of problems submitted --- anagram.py | 17 +++++++++++++++-- list_utils.py | 35 ++++++++++++++++++++++++++--------- palindrome.py | 9 ++++++++- string_utils.py | 25 +++++++++++++++++++------ 4 files changed, 68 insertions(+), 18 deletions(-) diff --git a/anagram.py b/anagram.py index c871147..66b2022 100644 --- a/anagram.py +++ b/anagram.py @@ -2,5 +2,18 @@ def is_anagram(first_string: str, second_string: str) -> bool: """ Given two strings, this functions determines if they are an anagram of one another. """ - pass # remove pass statement and implement me - + first1 = [] + second1 = [] + for i in first_string: + first1.append(i) + print('first1', first1) + for i in second_string: + second1.append(i) + print('second1',second1) + first1.sort() + second1.sort() + if first1 == second1: + return True + else: + return False +print(is_anagram('sea', 'aes')) \ No newline at end of file diff --git a/list_utils.py b/list_utils.py index aa417bf..f5294b1 100644 --- a/list_utils.py +++ b/list_utils.py @@ -10,7 +10,7 @@ def get_item_at_position(list_in: List, pos: int) -> List: :param pos: Position of desired item in list_in :return: Item in pos """ - pass # remove pass statement and implement me + return list_in[pos] # remove pass statement and implement me def print_list_items(list_in: List) -> None: @@ -20,7 +20,8 @@ def print_list_items(list_in: List) -> None: :param list_in: Input list :return: None """ - pass # remove pass statement and implement me + for i in list_in: + print(i) # remove pass statement and implement me def sort_by_commit_count(list_in: List) -> List: @@ -30,7 +31,8 @@ def sort_by_commit_count(list_in: List) -> List: :param list_in: A list where each entry is a list containing a name and the commit count corresponding to a user :return: The same list sorted in ascending order based on the commit count """ - pass # remove pass statement and implement me + list_in.sort() + return list_in # remove pass statement and implement me def gen_list_of_nums(n: int) -> List[int]: @@ -40,7 +42,10 @@ def gen_list_of_nums(n: int) -> List[int]: :param n: The number of items the result should contain :return: A list of integers """ - pass # remove pass statement and implement me + newList = [] + for i in range(n): + newList.append(i) + return newList # remove pass statement and implement me def half_list(list_in: List, half: int) -> List: @@ -52,7 +57,16 @@ def half_list(list_in: List, half: int) -> List: If the length of list_in is an odd number, round the half value up (hint: math.ceil()). :return: A list. """ - pass # remove pass statement and implement me + if len(list_in) % 2 == 0: + middle = len(list_in) / 2 + else: + middle = Math.ceil(len(list_in) / 2) + if half == 1: + return list_in[0, middle] + else: + return list_in[middle, len(list_in)] + + # remove pass statement and implement me def remove_odds(list_in: List[int]) -> None: @@ -61,7 +75,8 @@ def remove_odds(list_in: List[int]) -> None: :return: None """ - pass # remove pass statement and implement me + list_in = [x for x in list_in if x % 2 == 0] + #remove pass statement and implement me def remove_evens(list_in: List[int]) -> None: @@ -70,7 +85,7 @@ def remove_evens(list_in: List[int]) -> None: :return: None """ - pass # remove pass statement and implement me + list_in = [x for x in list_in if x % 2 != 0] # remove pass statement and implement me def concatenate_lists(list_a: List, list_b: List) -> List: @@ -81,7 +96,8 @@ def concatenate_lists(list_a: List, list_b: List) -> List: :param list_b: Another list :return: A list containing all elements from list_a and list_b """ - pass # remove pass statement and implement me + list_c = list_a + list_b + return list_c # remove pass statement and implement me def multiply_list(list_in: List, scalar: int) -> List: @@ -93,4 +109,5 @@ def multiply_list(list_in: List, scalar: int) -> List: :param scalar: An integer :return: A list """ - pass # remove pass statement and implement me + new_List = list_in * scalar + return new_List # remove pass statement and implement me diff --git a/palindrome.py b/palindrome.py index 1e94f57..484312f 100644 --- a/palindrome.py +++ b/palindrome.py @@ -5,4 +5,11 @@ def is_palindrome(value: str) -> bool: :param value: A string :return: A boolean """ - pass # remove pass statement and implement me + upperValue = value.upper() + reverseStr = upperValue[::-1] + if upperValue == reverseStr: + return True + else: + return False # remove pass statement and implement me + +print(is_palindrome('radar')) diff --git a/string_utils.py b/string_utils.py index 86174ef..83febcf 100644 --- a/string_utils.py +++ b/string_utils.py @@ -3,28 +3,32 @@ def str_len(str_in: str) -> str: """ Given a string parameter, this function should return the length of the parameter. """ - pass # remove pass statement and implement me + return len(str_in) # remove pass statement and implement me def first_char(str_in: str) -> str: """ Given a string parameter, this function should return the first letter of the parameter. """ - pass # remove pass statement and implement me + return str_in[0] # remove pass statement and implement me def last_char(str_in: str) -> str: """ Given a string parameter, this function should return the last letter of the parameter.. """ - pass # remove pass statement and implement me + return str_in[-1] # remove pass statement and implement me def input_has_substring(str_in: str, sub_str_in: str) -> bool: """ This function determines if the substring exists within the string. Returns True or False. """ - pass # remove pass statement and implement me + if sub_str_in in str_in: + return True + else: + return False + # remove pass statement and implement me def substring(str_in: str, start: int, stop: int) -> str: @@ -36,7 +40,7 @@ def substring(str_in: str, start: int, stop: int) -> str: start -- starting position of the input parameter to start the substring (inclusive) stop -- stopping position of the input parameter to stop the substring (exclusive) """ - pass # remove pass statement and implement me + return str_in[start:stop] # remove pass statement and implement me def opposite_case(str_in: str) -> str: @@ -45,4 +49,13 @@ def opposite_case(str_in: str) -> str: Example: When input = "Python" the function returns "pYTHON" """ - pass # remove pass statement and implement me + # remove pass statement and implement me + newStr = '' + for i in str_in: + if i == i.upper(): + newStr += i.lower() + else: + newStr += i.upper() + return newStr + + print(opposite_case('SeaN')) \ No newline at end of file From 3d1c366e4f66c2a727856229b73a539b495946b7 Mon Sep 17 00:00:00 2001 From: Sean Date: Fri, 25 Jun 2021 14:58:26 -0400 Subject: [PATCH 2/2] updated with 0 errors --- list_utils.py | 45 +++++++++++++++++++++++++++++++++++---------- palindrome.py | 15 +++++++++++---- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/list_utils.py b/list_utils.py index f5294b1..f06a57e 100644 --- a/list_utils.py +++ b/list_utils.py @@ -31,8 +31,14 @@ def sort_by_commit_count(list_in: List) -> List: :param list_in: A list where each entry is a list containing a name and the commit count corresponding to a user :return: The same list sorted in ascending order based on the commit count """ - list_in.sort() - return list_in # remove pass statement and implement me + list_in.sort(key = lambda x: x[1]) + return list_in + +print(sort_by_commit_count([['john', 15], + ['jane', 12], + ['dave', 10]])) + + def gen_list_of_nums(n: int) -> List[int]: @@ -57,15 +63,18 @@ def half_list(list_in: List, half: int) -> List: If the length of list_in is an odd number, round the half value up (hint: math.ceil()). :return: A list. """ - if len(list_in) % 2 == 0: - middle = len(list_in) / 2 - else: - middle = Math.ceil(len(list_in) / 2) + middle = len(list_in) // 2 + print(middle) if half == 1: - return list_in[0, middle] + if len(list_in) % 2 == 0: + return list_in[0: middle] + else: + return list_in[0: middle + 1] else: - return list_in[middle, len(list_in)] + return list_in[middle:] +print(half_list([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 2)) + # remove pass statement and implement me @@ -75,7 +84,15 @@ def remove_odds(list_in: List[int]) -> None: :return: None """ - list_in = [x for x in list_in if x % 2 == 0] + indexOfOdds = [] + for i in list_in: + if i % 2 != 0: + indexOfOdds.append(i) + print(indexOfOdds) + for i in indexOfOdds: + list_in.remove(i) + return list_in + #remove pass statement and implement me @@ -85,7 +102,15 @@ def remove_evens(list_in: List[int]) -> None: :return: None """ - list_in = [x for x in list_in if x % 2 != 0] # remove pass statement and implement me + indexOfEvens = [] + for i in list_in: + if i % 2 == 0: + indexOfEvens.append(i) + print(indexOfEvens) + for i in indexOfEvens: + list_in.remove(i) + return list_in + # remove pass statement and implement me def concatenate_lists(list_a: List, list_b: List) -> List: diff --git a/palindrome.py b/palindrome.py index 484312f..01a3e1c 100644 --- a/palindrome.py +++ b/palindrome.py @@ -7,9 +7,16 @@ def is_palindrome(value: str) -> bool: """ upperValue = value.upper() reverseStr = upperValue[::-1] - if upperValue == reverseStr: + newReverse = '' + newUpper = '' + for i in reverseStr: + if i != ' ': + newReverse += i + for i in upperValue: + if i != ' ': + newUpper += i + if newUpper == newReverse: return True else: - return False # remove pass statement and implement me - -print(is_palindrome('radar')) + return False # remove pass statement and +print(is_palindrome('Do geese see God')) \ No newline at end of file