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
10 changes: 10 additions & 0 deletions Week03/pyramid_sefa_sagirli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def calculate_pyramid_height(number_of_blocks):
"""Return the height of the pyramid that can be built with the given blocks.

Each level i needs i blocks (1 on top, 2 below it, and so on).
"""
height = 0
while number_of_blocks >= height + 1:
height += 1
number_of_blocks -= height
return height
20 changes: 20 additions & 0 deletions Week03/sequences_sefa_sagirli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def remove_duplicates(seq: list) -> list:
"""Return a new list without duplicates, keeping the original order."""
result = []
for item in seq:
if item not in result:
result.append(item)
return result


def list_counts(seq: list) -> dict:
"""Return a dictionary with the number of occurrences of each item."""
counts = {}
for item in seq:
counts[item] = counts.get(item, 0) + 1
return counts


def reverse_dict(d: dict) -> dict:
"""Return a dictionary with keys and values swapped."""
return {value: key for key, value in d.items()}
Loading