diff --git a/Week01/info_ertugrul_kose.py b/Week01/info_ertugrul_kose.py new file mode 100644 index 00000000..301759a2 --- /dev/null +++ b/Week01/info_ertugrul_kose.py @@ -0,0 +1,2 @@ +student_id = "210316038" +full_name = "Ertuğrul Köse" diff --git a/Week02/types_ertugrul_kose.py b/Week02/types_ertugrul_kose.py new file mode 100644 index 00000000..cf628a8f --- /dev/null +++ b/Week02/types_ertugrul_kose.py @@ -0,0 +1,4 @@ +my_int = 9 +my_float = 11.4 +my_bool = True +my_complex = 9j diff --git a/Week03/pyramid_ertugrul_kose.py b/Week03/pyramid_ertugrul_kose.py new file mode 100644 index 00000000..83d7da7d --- /dev/null +++ b/Week03/pyramid_ertugrul_kose.py @@ -0,0 +1,6 @@ +def calculate_pyramid_height(blocks): + h = 0 + while blocks > h: + h += 1 + blocks -= h + return h diff --git a/Week03/sequences_ertugrul_kose.py b/Week03/sequences_ertugrul_kose.py new file mode 100644 index 00000000..c056a0d3 --- /dev/null +++ b/Week03/sequences_ertugrul_kose.py @@ -0,0 +1,34 @@ +def remove_duplicates(seq: list) -> list: + """ + This function removes duplicates from a list. + """ + unique = [] + for x in seq: + if x not in unique: + unique.append(x) + return unique + + +def list_counts(seq: list) -> dict: + """ + This function counts the number of + occurrences of each item in a list. + """ + result = {} + for x in seq: + if x in result: + result[x] += 1 + else: + result[x] = 1 + return result + + +def reverse_dict(d: dict) -> dict: + """ + This function reverses the keys + and values of a dictionary + """ + rev = {} + for k, v in d.items(): + rev[v] = k + return rev diff --git a/Week04/decorators_ertugrul_kose.py b/Week04/decorators_ertugrul_kose.py new file mode 100644 index 00000000..4d49d388 --- /dev/null +++ b/Week04/decorators_ertugrul_kose.py @@ -0,0 +1,30 @@ +import tracemalloc as tm +from time import time as current_time + + +def performance(func): + """ + Decorator that gathers call count, execution time and memory usage. + """ + + performance.count = 0 + performance.time_total = 0.0 + performance.mem_total = 0.0 + + def wrapper(*args, **kwargs): + tm.start() + + start = current_time() + result = func(*args, **kwargs) + end = current_time() + + mem_now, mem_peak = tm.get_traced_memory() + tm.stop() + + performance.count += 1 + performance.time_total += (end - start) + performance.mem_total += mem_peak + + return result + + return wrapper