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 diff --git a/Week03/sequences_sinem_tanriver.py b/Week03/sequences_sinem_tanriver.py new file mode 100644 index 000000000..4b99b024a --- /dev/null +++ b/Week03/sequences_sinem_tanriver.py @@ -0,0 +1,28 @@ +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. + """ + 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 {value: key for key, value in d.items()}