Skip to content

Commit 683e73b

Browse files
authored
Merge pull request canbula#691 from sinemtanriver/patch-2
Add function to calculate pyramid height
2 parents f083b29 + 6adcc14 commit 683e73b

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎Week03/pyramid_sinem_tanriver.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def calculate_pyramid_height(number_of_blocks):
2+
height = 0
3+
for row in range(1, number_of_blocks + 1):
4+
if number_of_blocks < row:
5+
break
6+
number_of_blocks -= row
7+
height += 1
8+
return height

‎Week03/sequences_sinem_tanriver.py‎

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

0 commit comments

Comments
 (0)