diff --git a/Week03/pyramid_esra_sepik.py b/Week03/pyramid_esra_sepik.py new file mode 100644 index 000000000..98ce056b2 --- /dev/null +++ b/Week03/pyramid_esra_sepik.py @@ -0,0 +1,7 @@ +def calculate_pyramid_height(number_of_blocks): + height = 0 + used_blocks = 0 + while used_blocks + (height + 1) <= number_of_blocks: + height += 1 + used_blocks += height + return height diff --git a/Week03/sequences_esra_sepik.py b/Week03/sequences_esra_sepik.py new file mode 100644 index 000000000..1cb5d5906 --- /dev/null +++ b/Week03/sequences_esra_sepik.py @@ -0,0 +1,22 @@ +def remove_duplicates(seq: list) -> list: + """ + This function removes duplicates from a list. + """ + return list(dict.fromkeys(seq)) + + +def list_counts(seq: list) -> dict: + """ + This function counts the number of occurrences of each item in a list. + """ + return {item: seq.count(item) for item in seq} + + +def reverse_dict(d: dict) -> dict: + """ + This function reverses the keys and values of a dictionary. + """ + reversed_d = {} + for key, value in d.items(): + reversed_d[value] = key + return reversed_d