[Python3] group-by-group
Please pull this commit for solutions of weekly 292. \n\n\nclass Solution:\n    def countTexts(self, pressedKeys: str) -> int:\n        MOD = 1_000_000_007 \n  
Please pull this [commit](https://github.com/gaosanyong/leetcode/commit/9aa0edb0815f3e0a75a47808e1690ca424f169e5) for solutions of weekly 292. \n\n```\nclass Solution:\n    def countTexts(self, pressedKeys: str) -> int:\n        MOD = 1_000_000_007 \n        \n        @cache \n        def fn(n, k): \n            """Return number of possible text of n repeated k times."""\n            if n < 0: return 0\n            if n == 0: return 1\n            ans = 0\n            for x in range(1, k+1): ans = (ans + fn(n-x, k)) % MOD\n            return ans \n        \n        ans = 1\n        for key, grp in groupby(pressedKeys): \n            if key in "79": k = 4\n            else: k = 3\n            ans = (ans * fn(len(list(grp)), k)) % MOD \n        return ans \n```\n\nAdded a shorter implementation \n```\nclass Solution:\n    def countTexts(self, pressedKeys: str) -> int:\n        dp = [0] * (len(pressedKeys)+1)\n        dp[0] = 1\n        for i, ch in enumerate(pressedKeys):\n            dp[i+1] = dp[i]\n            if i and pressedKeys[i-1] == ch: \n                dp[i+1] += dp[i-1]\n                if i >= 2 and pressedKeys[i-2] == ch: \n                    dp[i+1] += dp[i-2]\n                    if i >= 3 and pressedKeys[i-3] == ch and ch in "79": dp[i+1] += dp[i-3]\n            dp[i+1] %= 1_000_000_007\n        return dp[-1]\n```
['Python3']