Skip to content
Open
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_berzan_gecit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
my_int = 72
my_float = 7.2
my_bool = False
my_complex = 7+2j
6 changes: 6 additions & 0 deletions Week03/pyramid_berzan_gecit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def calculate_pyramid_height(number_of_blocks):
height = 0
while number_of_blocks >= height + 1:
height += 1
number_of_blocks -= height
return height
22 changes: 22 additions & 0 deletions Week03/sequences_berzan_gecit.py
Original file line number Diff line number Diff line change
@@ -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.
"""
counts = {}
for item in seq:
counts[item] = counts.get(item, 0) + 1
return counts


def reverse_dict(d: dict) -> dict:
"""
This function reverses the keys and values of a dictionary.
"""
return {value: key for key, value in d.items()}
30 changes: 30 additions & 0 deletions Week04/decorators_berzan_gecit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import functools
import time
import tracemalloc


def performance(fn):
@functools.wraps(fn)
def wrapper(*args, **kwargs):
performance.counter += 1
was_tracing = tracemalloc.is_tracing()
if not was_tracing:
tracemalloc.start()
tracemalloc.reset_peak()
start_mem = tracemalloc.get_traced_memory()[0]
start = time.perf_counter()
try:
return fn(*args, **kwargs)
finally:
performance.total_time += time.perf_counter() - start
peak = tracemalloc.get_traced_memory()[1]
performance.total_mem += max(0, peak - start_mem)
if not was_tracing:
tracemalloc.stop()

return wrapper


performance.counter = 0
performance.total_time = 0
performance.total_mem = 0
30 changes: 30 additions & 0 deletions Week04/functions_berzan_gecit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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 (x**a + y**b) / c.

:param x: first base (positional-only)
:param y: second base (positional-only)
:param a: exponent of x
:param b: exponent of y
:param c: divisor (keyword-only)
:return: the result of (x**a + y**b) / c
"""
if not all(isinstance(v, int) for v in (x, y, a, b, c)):
raise TypeError("All arguments must be integers")
return (x**a + y**b) / c


def fn_w_counter() -> (int, dict[str, int]):

fn_w_counter.calls += 1
fn_w_counter.callers[__name__] = fn_w_counter.callers.get(__name__, 0) + 1
return fn_w_counter.calls, dict(fn_w_counter.callers)


fn_w_counter.calls = 0
fn_w_counter.callers = {}
31 changes: 31 additions & 0 deletions Week05/emails_berzan_gecit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import re


class Emails(list):

_pattern = re.compile(r"[\w.+-]+@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)+")

def __init__(self, emails=None):
super().__init__()
emails = [] if emails is None else list(emails)
self.validate(emails)
for email in emails:
if email not in self:
self.append(email)

@property
def data(self):
return self

def validate(self, emails):
for email in emails:
if not isinstance(email, str):
raise ValueError("Emails must be strings")
if not self._pattern.fullmatch(email):
raise ValueError(f"Invalid email address: {email}")

def __repr__(self):
return f"Emails({list.__repr__(self)})"

def __str__(self):
return ", ".join(self)