diff --git a/src/tools/types.py b/src/tools/types.py index ddd56ba..6fa50a5 100644 --- a/src/tools/types.py +++ b/src/tools/types.py @@ -1,5 +1,6 @@ from __future__ import annotations from collections.abc import Iterable +from math import ceil class Integer(int): @@ -33,6 +34,19 @@ class String(str): def __getitem__(self, item) -> String: return String(super().__getitem__(item)) + def __floordiv__(self, other: int) -> list[String]: + d = ceil(len(self) / other) + return [self[i * d:i * d + d] for i in range(other)] + + + def __truediv__(self, other: int) -> list[String]: + if len(self) % other != 0: + raise ValueError("String length is Not a multiple of {}".format(other)) + + d = len(self) // other + return [self[i * d:i * d + d] for i in range(other)] + + class List(list): def moving_window(self, size: int = 2) -> Iterable[List]: