Skip to content

Commit 0f6aa50

Browse files
committed
Add Week03 pyramid and sequence assignments
1 parent 9a399e7 commit 0f6aa50

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎Week03/pyramid_beyza_arman.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def calculate_pyramid_height(blocks):
2+
"""Return the number of complete layers that can be built."""
3+
height = 0
4+
next_layer = 1
5+
while blocks >= next_layer:
6+
blocks -= next_layer
7+
height += 1
8+
next_layer += 1
9+
return height

‎Week03/sequences_beyza_arman.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def remove_duplicates(items):
2+
"""Remove duplicates while preserving the first occurrence order."""
3+
result = []
4+
for item in items:
5+
if item not in result:
6+
result.append(item)
7+
return result
8+
9+
10+
def list_counts(items):
11+
"""Return the frequency of each item."""
12+
counts = {}
13+
for item in items:
14+
counts[item] = counts.get(item, 0) + 1
15+
return counts
16+
17+
18+
def reverse_dict(mapping):
19+
"""Swap keys and values; the last key wins for repeated values."""
20+
return {value: key for key, value in mapping.items()}

0 commit comments

Comments
 (0)