From 054e654c63491fb882e60d2ccf7261f81b63b949 Mon Sep 17 00:00:00 2001 From: sinemtanriver Date: Thu, 15 Oct 2026 14:27:17 +0300 Subject: [PATCH 1/3] Add function to calculate pyramid height --- Week03/pyramid_sinem_tanriver.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Week03/pyramid_sinem_tanriver.py diff --git a/Week03/pyramid_sinem_tanriver.py b/Week03/pyramid_sinem_tanriver.py new file mode 100644 index 000000000..84b9572fa --- /dev/null +++ b/Week03/pyramid_sinem_tanriver.py @@ -0,0 +1,8 @@ +def calculate_pyramid_height(number_of_blocks): + height = 0 + for row in range(1, number_of_blocks + 1): + if number_of_blocks < row: + break + number_of_blocks -= row + height += 1 + return height From 9a5c6785aab44de7c2e4388a5457b043c3ea5370 Mon Sep 17 00:00:00 2001 From: sinemtanriver Date: Thu, 15 Oct 2026 14:33:53 +0300 Subject: [PATCH 2/3] Implement utility functions for list and dict operations Added functions to remove duplicates, count occurrences, and reverse dictionaries. --- Week03/sequences_sinem_tanriver.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Week03/sequences_sinem_tanriver.py diff --git a/Week03/sequences_sinem_tanriver.py b/Week03/sequences_sinem_tanriver.py new file mode 100644 index 000000000..b92ed8254 --- /dev/null +++ b/Week03/sequences_sinem_tanriver.py @@ -0,0 +1,28 @@ +from collections import Counter + + +def remove_duplicates(seq: list) -> list: + """ + This function removes duplicates from a list. + """ + seen = set() + unique = [] + for item in seq: + if item not in seen: + seen.add(item) + unique.append(item) + return unique + + +def list_counts(seq: list) -> dict: + """ + This function counts the number of occurrences of each item in a list. + """ + return dict(Counter(seq)) + + +def reverse_dict(d: dict) -> dict: + """ + This function reverses the keys and values of a dictionary. + """ + return dict(zip(d.values(), d.keys())) From 6adcc14b781ec15095b78314867e326ea98db146 Mon Sep 17 00:00:00 2001 From: sinemtanriver Date: Wed, 28 Oct 2026 14:23:48 +0300 Subject: [PATCH 3/3] Remove Counter import, solve without modules --- Week03/sequences_sinem_tanriver.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Week03/sequences_sinem_tanriver.py b/Week03/sequences_sinem_tanriver.py index b92ed8254..4b99b024a 100644 --- a/Week03/sequences_sinem_tanriver.py +++ b/Week03/sequences_sinem_tanriver.py @@ -1,6 +1,3 @@ -from collections import Counter - - def remove_duplicates(seq: list) -> list: """ This function removes duplicates from a list. @@ -18,11 +15,14 @@ def list_counts(seq: list) -> dict: """ This function counts the number of occurrences of each item in a list. """ - return dict(Counter(seq)) + counts = {} + for item in seq: + counts[item] = counts.get(item, 0) + 1 + return counts def reverse_dict(d: dict) -> dict: """ This function reverses the keys and values of a dictionary. """ - return dict(zip(d.values(), d.keys())) + return {value: key for key, value in d.items()}