diff --git a/Week02/types_kayraemre_karaosmanoglu.py b/Week02/types_kayraemre_karaosmanoglu.py new file mode 100644 index 00000000..94592295 --- /dev/null +++ b/Week02/types_kayraemre_karaosmanoglu.py @@ -0,0 +1,4 @@ +my_int = 74 +my_float = 3.34 +my_bool = False +my_complex = 3 + 4j diff --git a/Week03/pyramid_kayraemre_karaosmanoglu.py b/Week03/pyramid_kayraemre_karaosmanoglu.py new file mode 100644 index 00000000..f06be4ae --- /dev/null +++ b/Week03/pyramid_kayraemre_karaosmanoglu.py @@ -0,0 +1,10 @@ +def calculate_pyramid_height(number_of_blocks): + height = 0 + layer_blocks = 1 + + while number_of_blocks >= layer_blocks: + number_of_blocks -= layer_blocks + height += 1 + layer_blocks += 1 + + return height diff --git a/Week03/sequences_kayraemre_karaosmanoglu.py b/Week03/sequences_kayraemre_karaosmanoglu.py new file mode 100644 index 00000000..43b079ec --- /dev/null +++ b/Week03/sequences_kayraemre_karaosmanoglu.py @@ -0,0 +1,12 @@ +def remove_duplicates(seq: list) -> list: + + return list(dict.fromkeys(seq)) + +def list_counts(seq: list) -> dict: + counts = {} + for item in seq: + counts[item] = counts.get(item, 0) + 1 + return counts + +def reverse_dict(d: dict) -> dict: + return {value: key for key, value in d.items()} diff --git a/Week04/decorators_kayraemre_karaosmanoglu.py b/Week04/decorators_kayraemre_karaosmanoglu.py new file mode 100644 index 00000000..15069a60 --- /dev/null +++ b/Week04/decorators_kayraemre_karaosmanoglu.py @@ -0,0 +1,22 @@ +import time +import tracemalloc + +def performance(func): + def _performance(*args, **kwargs): + tracemalloc.start() + start = time.perf_counter() + result = func(*args, **kwargs) + end = time.perf_counter() + _, peak = tracemalloc.get_traced_memory() + tracemalloc.stop() + + performance.counter += 1 + performance.total_time += end - start + performance.total_mem += peak + return result + + return _performance + +performance.counter = 0 +performance.total_time = 0 +performance.total_mem = 0 diff --git a/Week04/functions_kayraemre_karaosmanoglu.py b/Week04/functions_kayraemre_karaosmanoglu.py new file mode 100644 index 00000000..16bf3bc1 --- /dev/null +++ b/Week04/functions_kayraemre_karaosmanoglu.py @@ -0,0 +1,27 @@ +custom_power = lambda x=0, /, e=1: x ** e + +def custom_equation(x: int=0, y: int=0, /, a: int=1, b: int=1, *, c: int=1) -> float: + """ + This function does arithmetic opearations. + + :param1: first number to be exponantiated + :param2: second number to be exponantiated + :param3: power of the first number + :param4: power of the second number + :param5: divisor of sum of exponantiated numbers + + :return: division the sum of exponantiated numbers + """ + return (x**a + y**b) / c + +call_counter = 0 +caller_dict = {} +def fn_w_counter() -> (int, dict[str, int]): + caller = __name__ + global call_counter + call_counter += 1 + if caller in caller_dict: + caller_dict[caller] += 1 + else: + caller_dict[caller] = 1 + return call_counter, caller_dict diff --git a/Week05/emails_kayraemre_karaosmanoglu.py b/Week05/emails_kayraemre_karaosmanoglu.py new file mode 100644 index 00000000..010f9c4c --- /dev/null +++ b/Week05/emails_kayraemre_karaosmanoglu.py @@ -0,0 +1,30 @@ +import re + + +class Emails(list): + + EMAIL_PATTERN = re.compile(r"[^@\s]+@[^@\s]+\.[^@\s]+") + + def __init__(self, emails): + super().__init__() + self.validate(emails) + for email in emails: + if email not in self: # tekrar edenleri ekleme + self.append(email) + + @property + def data(self): + return list(self) + + def validate(self, emails): + for email in emails: + if not isinstance(email, str): + raise ValueError(f"{email!r} is not a string") + if not self.EMAIL_PATTERN.fullmatch(email): + raise ValueError(f"{email!r} is not a valid email address") + + def __repr__(self): + return f"Emails({list.__repr__(self)})" + + def __str__(self): + return ", ".join(self)