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
4 changes: 4 additions & 0 deletions Week02/types_kayraemre_karaosmanoglu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
my_int = 74
my_float = 3.34
my_bool = False
my_complex = 3 + 4j
10 changes: 10 additions & 0 deletions Week03/pyramid_kayraemre_karaosmanoglu.py
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions Week03/sequences_kayraemre_karaosmanoglu.py
Original file line number Diff line number Diff line change
@@ -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()}
22 changes: 22 additions & 0 deletions Week04/decorators_kayraemre_karaosmanoglu.py
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions Week04/functions_kayraemre_karaosmanoglu.py
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions Week05/emails_kayraemre_karaosmanoglu.py
Original file line number Diff line number Diff line change
@@ -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)
Loading