Skip to content

Commit 5427e11

Browse files
committed
Week03: pyramid ve sequences ödevleri eklendi
1 parent 93f8dd6 commit 5427e11

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎Week03/pyramid_sefa_sagirli.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def calculate_pyramid_height(number_of_blocks):
2+
"""Return the height of the pyramid that can be built with the given blocks.
3+
4+
Each level i needs i blocks (1 on top, 2 below it, and so on).
5+
"""
6+
height = 0
7+
while number_of_blocks >= height + 1:
8+
height += 1
9+
number_of_blocks -= height
10+
return height

‎Week03/sequences_sefa_sagirli.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def remove_duplicates(seq: list) -> list:
2+
"""Return a new list without duplicates, keeping the original order."""
3+
result = []
4+
for item in seq:
5+
if item not in result:
6+
result.append(item)
7+
return result
8+
9+
10+
def list_counts(seq: list) -> dict:
11+
"""Return a dictionary with the number of occurrences of each item."""
12+
counts = {}
13+
for item in seq:
14+
counts[item] = counts.get(item, 0) + 1
15+
return counts
16+
17+
18+
def reverse_dict(d: dict) -> dict:
19+
"""Return a dictionary with keys and values swapped."""
20+
return {value: key for key, value in d.items()}

0 commit comments

Comments
 (0)