Skip to content
Merged

HW3 #946

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
9 changes: 9 additions & 0 deletions Week03/pyramid_gokhan_koray_bulbul.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def calculate_pyramid_height(number_of_blocks):
# Input precautions
if (not isinstance(number_of_blocks, int)) or (number_of_blocks < 0):
raise TypeError("number_of_blocks must be a non-negative whole integer.")

height = 1
while True:
if(number_of_blocks := number_of_blocks - height) <= height: return height
height += 1
21 changes: 21 additions & 0 deletions Week03/sequences_gokhan_koray_bulbul.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def remove_duplicates(seq: list) -> list:
# returning list(set(seq)) would not preserve order
unique_set = set()
result = []
for item in seq:
if item not in unique_set:
result.append(item)
unique_set.add(item)
return result

def list_counts(seq: list) -> dict:
occurance_dict = dict.fromkeys(seq, 0)
for item in seq:
occurance_dict[item] += 1
return occurance_dict

def reverse_dict(d: dict) -> dict:
reversed_dict = dict()
for key, value in d.items():
reversed_dict[value] = key
return reversed_dict