from pprint import pprint
import re
x = ['this is a foo bar', 'you are a foo bar black sheep']

def words_and_char_bigrams(text):
    words = re.findall('\\w{3,}', text)
for w in words:
    yield w
for i in range(len(w) - 2):
    yield w[i:i + 2]
v = CountVectorizer(analyzer=words_and_char_bigrams)
pprint(v.fit(x).vocabulary_)
How do I use sklearn CountVectorizer with both 'word' and 'char' analyzer? - python