def sliding(a, n): return (a[i:i+n] for i in xrange(len(a) - n + 1))def substring_count(a, b): return sum(s == b for s in sliding(a, len(b)))assert list(sliding('abcde', 3)) == ['abc', 'bcd', 'cde'] assert substring_count('ababaa', 'aba') == 2
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)