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..f06a57e 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,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 """ - pass # 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]: @@ -40,7 +48,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 +63,19 @@ 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 + middle = len(list_in) // 2 + print(middle) + if half == 1: + if len(list_in) % 2 == 0: + return list_in[0: middle] + else: + return list_in[0: middle + 1] + else: + return list_in[middle:] + +print(half_list([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 2)) + + # remove pass statement and implement me def remove_odds(list_in: List[int]) -> None: @@ -61,7 +84,16 @@ def remove_odds(list_in: List[int]) -> None: :return: None """ - pass # remove pass statement and implement me + 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 def remove_evens(list_in: List[int]) -> None: @@ -70,7 +102,15 @@ def remove_evens(list_in: List[int]) -> None: :return: None """ - pass # 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: @@ -81,7 +121,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 +134,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..01a3e1c 100644 --- a/palindrome.py +++ b/palindrome.py @@ -5,4 +5,18 @@ 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] + 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 +print(is_palindrome('Do geese see God')) \ No newline at end of file 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