def character_ngrams(string="", n=3, top=None, threshold=0, exclude=[], **kwargs):
    # An optional dict-parameter can be used to specify a subclass of dict, 
    # e.g., count(words, dict=readonlydict) as used in Document.
    count = defaultdict(int)
    if n > 0:
        for i in xrange(len(string)-n+1):
            w = string[i:i+n]
            if w not in exclude:
                count[w] += 1
    if threshold > 0:
        count = dict((k, v) for k, v in count.items() if v > threshold)
    if top is not None:
        count = dict(heapq.nsmallest(top, count.items(), key=lambda kv: (-kv[1], kv[0])))
    return kwargs.get("dict", dict)(count)
Returns a dictionary of (character n-gram, count)-items.
dataset/ETHPy150Open clips/pattern/pattern/vector/__init__.py/character_ngrams