python中split控制划分的次数

python中split控制划分的次数_第1张图片

class Solution(object):
    def subdomainVisits(self, cpdomains):
        """
        :type cpdomains: List[str]
        :rtype: List[str]
        """
        
        res = {}
        for case in cpdomains:
            time, domain = case.split()
            length = len(domain.split('.'))
            for num in range(length):
                dm = domain.split('.', num)[-1]
                res[dm] = res.get(dm, 0) + int(time)
        return [str(v)+' '+k for k, v in res.items()]

你可能感兴趣的:(leecode,哈希表,leetcode,字符串)