Skip to content

Commit d717c64

Browse files
authored
Merge pull request #930 from Shar0x/master
Create types_kayraemre_karaosmanoglu.py
2 parents 1fac0cd + 760c98a commit d717c64

6 files changed

Lines changed: 105 additions & 0 deletions
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
my_int = 74
2+
my_float = 3.34
3+
my_bool = False
4+
my_complex = 3 + 4j
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def calculate_pyramid_height(number_of_blocks):
2+
height = 0
3+
layer_blocks = 1
4+
5+
while number_of_blocks >= layer_blocks:
6+
number_of_blocks -= layer_blocks
7+
height += 1
8+
layer_blocks += 1
9+
10+
return height
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def remove_duplicates(seq: list) -> list:
2+
3+
return list(dict.fromkeys(seq))
4+
5+
def list_counts(seq: list) -> dict:
6+
counts = {}
7+
for item in seq:
8+
counts[item] = counts.get(item, 0) + 1
9+
return counts
10+
11+
def reverse_dict(d: dict) -> dict:
12+
return {value: key for key, value in d.items()}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import time
2+
import tracemalloc
3+
4+
def performance(func):
5+
def _performance(*args, **kwargs):
6+
tracemalloc.start()
7+
start = time.perf_counter()
8+
result = func(*args, **kwargs)
9+
end = time.perf_counter()
10+
_, peak = tracemalloc.get_traced_memory()
11+
tracemalloc.stop()
12+
13+
performance.counter += 1
14+
performance.total_time += end - start
15+
performance.total_mem += peak
16+
return result
17+
18+
return _performance
19+
20+
performance.counter = 0
21+
performance.total_time = 0
22+
performance.total_mem = 0
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
custom_power = lambda x=0, /, e=1: x ** e
2+
3+
def custom_equation(x: int=0, y: int=0, /, a: int=1, b: int=1, *, c: int=1) -> float:
4+
"""
5+
This function does arithmetic opearations.
6+
7+
:param1: first number to be exponantiated
8+
:param2: second number to be exponantiated
9+
:param3: power of the first number
10+
:param4: power of the second number
11+
:param5: divisor of sum of exponantiated numbers
12+
13+
:return: division the sum of exponantiated numbers
14+
"""
15+
return (x**a + y**b) / c
16+
17+
call_counter = 0
18+
caller_dict = {}
19+
def fn_w_counter() -> (int, dict[str, int]):
20+
caller = __name__
21+
global call_counter
22+
call_counter += 1
23+
if caller in caller_dict:
24+
caller_dict[caller] += 1
25+
else:
26+
caller_dict[caller] = 1
27+
return call_counter, caller_dict
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import re
2+
3+
4+
class Emails(list):
5+
6+
EMAIL_PATTERN = re.compile(r"[^@\s]+@[^@\s]+\.[^@\s]+")
7+
8+
def __init__(self, emails):
9+
super().__init__()
10+
self.validate(emails)
11+
for email in emails:
12+
if email not in self: # tekrar edenleri ekleme
13+
self.append(email)
14+
15+
@property
16+
def data(self):
17+
return list(self)
18+
19+
def validate(self, emails):
20+
for email in emails:
21+
if not isinstance(email, str):
22+
raise ValueError(f"{email!r} is not a string")
23+
if not self.EMAIL_PATTERN.fullmatch(email):
24+
raise ValueError(f"{email!r} is not a valid email address")
25+
26+
def __repr__(self):
27+
return f"Emails({list.__repr__(self)})"
28+
29+
def __str__(self):
30+
return ", ".join(self)

0 commit comments

Comments
 (0)