1759. Count Number of Homogenous Substrings

class Solution:
    def countHomogenous(self, s: str) -> int:
        MOD = (10**9) + 7
        homos = defaultdict(int)
        t = ""
        prev = s[0]

        for e in s:            
            if e == prev:
                t += e                
            else:
                homos[t] += 1
                t = e
                prev = e 
        homos[t] += 1

        s = 0
        for e in list(homos.keys()):
            l = len(e)
            x = (l * (l + 1)) // 2
            s += (x * homos[e])
        return s % MOD