Skip to content

Commit 18da381

Browse files
authored
Merge pull request #690 from EsraSepik/patch-3
Add function to calculate pyramid height
2 parents e18e9cc + 945f7c8 commit 18da381

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎Week03/pyramid_esra_sepik.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def calculate_pyramid_height(number_of_blocks):
2+
height = 0
3+
used_blocks = 0
4+
while used_blocks + (height + 1) <= number_of_blocks:
5+
height += 1
6+
used_blocks += height
7+
return height

‎Week03/sequences_esra_sepik.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def remove_duplicates(seq: list) -> list:
2+
"""
3+
This function removes duplicates from a list.
4+
"""
5+
return list(dict.fromkeys(seq))
6+
7+
8+
def list_counts(seq: list) -> dict:
9+
"""
10+
This function counts the number of occurrences of each item in a list.
11+
"""
12+
return {item: seq.count(item) for item in seq}
13+
14+
15+
def reverse_dict(d: dict) -> dict:
16+
"""
17+
This function reverses the keys and values of a dictionary.
18+
"""
19+
reversed_d = {}
20+
for key, value in d.items():
21+
reversed_d[value] = key
22+
return reversed_d

0 commit comments

Comments
 (0)