From a9d7d1b0244363e0f8cbd458faed858192859d47 Mon Sep 17 00:00:00 2001 From: YasarMert <95618275+YasarMert@users.noreply.github.com.> Date: Wed, 18 Nov 2026 21:44:52 +0300 Subject: [PATCH] Added decorators_yasarmert_turkmen.py, emails_yasarmert_turkmen.py and functions_yasarmert_turkmen.py --- Week04/decorators_yasarmert_turkmen.py | 26 +++++++++++++++++++++ Week04/functions_yasarmert_turkmen.py | 26 +++++++++++++++++++++ Week05/emails_yasarmert_turkmen.py | 32 ++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 Week04/decorators_yasarmert_turkmen.py create mode 100644 Week04/functions_yasarmert_turkmen.py create mode 100644 Week05/emails_yasarmert_turkmen.py diff --git a/Week04/decorators_yasarmert_turkmen.py b/Week04/decorators_yasarmert_turkmen.py new file mode 100644 index 00000000..b47059ba --- /dev/null +++ b/Week04/decorators_yasarmert_turkmen.py @@ -0,0 +1,26 @@ +import time +import tracemalloc + + +def performance(func): + def wrapper(*args, **kwargs): + performance.counter += 1 + start_time = time.perf_counter() + tracemalloc.start() + + result = func(*args, **kwargs) + + current_mem, _ = tracemalloc.get_traced_memory() + tracemalloc.stop() + end_time = time.perf_counter() + + performance.total_time += end_time - start_time + performance.total_mem += current_mem + return result + + return wrapper + + +performance.counter = 0 +performance.total_time = 0.0 +performance.total_mem = 0 \ No newline at end of file diff --git a/Week04/functions_yasarmert_turkmen.py b/Week04/functions_yasarmert_turkmen.py new file mode 100644 index 00000000..8f71be82 --- /dev/null +++ b/Week04/functions_yasarmert_turkmen.py @@ -0,0 +1,26 @@ +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: + """ + Calculates a custom equation + + :param x: Base value for the first term. The default value is 0 + :param y: Base value for the second term. The default value is 0 + :param a: Exponent for the first term. The defaults value is 1. + :param b: Exponent for the second term. The defaults value is 1. + :param c: The divisor. The default value is 1 + :return: Returns the float number that is the result of the calculated custom equation. + """ + return (x**a + y**b) / c + +def fn_w_counter() -> (int, dict[str,int]): + if not hasattr(fn_w_counter, "total_calls"): + fn_w_counter.total_calls = 0 + fn_w_counter.caller_dict = {} + + caller = __name__ + + fn_w_counter.total_calls += 1 + fn_w_counter.caller_dict[caller] = fn_w_counter.caller_dict.get(caller, 0) + 1 + + return fn_w_counter.total_calls, fn_w_counter.caller_dict diff --git a/Week05/emails_yasarmert_turkmen.py b/Week05/emails_yasarmert_turkmen.py new file mode 100644 index 00000000..928b9b7d --- /dev/null +++ b/Week05/emails_yasarmert_turkmen.py @@ -0,0 +1,32 @@ +class Emails(list): + def __init__(self, emails=[]): + clean_email_list = self.validate(emails) + super().__init__(clean_email_list) + self.data = self + + def validate(self, emails): + unique_emails = [] + for email in emails: + if not isinstance(email, str): + raise ValueError("The email must be a string!") + if email.count('@') != 1: + raise ValueError("Invalid email format. There can't be more than 1 @ symbol!") + name, domain = email.split('@') + if not name: + raise ValueError("Invalid email format. The part before the @ (the name) is missing!") + if not domain: + raise ValueError("Invalid email format. The part after the @ (the domain) is missing!") + if '.' not in domain: + raise ValueError("Invalid email format. The part after the @ (the domain) is missing it's dot!") + if domain.startswith('.') or domain.endswith('.'): + raise ValueError("Invalid email format.") + if email not in unique_emails: + unique_emails.append(email) + return unique_emails + + def __repr__(self): + return f"Emails({list(self)})" + + def __str__(self): + return ", ".join(self) +