Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Week04/decorators_yasarmert_turkmen.py
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions Week04/functions_yasarmert_turkmen.py
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions Week05/emails_yasarmert_turkmen.py
Original file line number Diff line number Diff line change
@@ -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)

Loading