Python Elegant & Short | Pythonic | Iterative + Recursive
\tclass Solution:\n\t\tdef digitSum(self, s: str, k: int) -> str:\n\t\t\t"""Iterative version"""\n\t\t\twhile len(s) > k:\n\t\t\t\ts = self.round(s, k)\n\t\t\tr
\tclass Solution:\n\t\tdef digitSum(self, s: str, k: int) -> str:\n\t\t\t"""Iterative version"""\n\t\t\twhile len(s) > k:\n\t\t\t\ts = self.round(s, k)\n\t\t\treturn s\n\t\n\t\tdef digitSum(self, s: str, k: int) -> str:\n\t\t\t"""Recursive version"""\n\t\t\tif len(s) <= k:\n\t\t\t\treturn s\n\t\t\treturn self.digitSum(self.round(s, k), k)\n\n\t\t@classmethod\n\t\tdef round(cls, s: str, k: int) -> str:\n\t\t\treturn \'\'.join(map(cls.add_digits, cls.slice(s, k)))\n\n\t\t@staticmethod\n\t\tdef add_digits(s: str) -> str:\n\t\t\treturn str(sum(int(d) for d in s))\n\n\t\t@staticmethod\n\t\tdef slice(s: str, k: int):\n\t\t\tfor i in range(0, len(s), k):\n\t\t\t\tyield s[i:i + k]\n
['Python', 'Python3']