Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions anagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
60 changes: 51 additions & 9 deletions list_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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]:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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
16 changes: 15 additions & 1 deletion palindrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
25 changes: 19 additions & 6 deletions string_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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'))