I'm trying to turn this into two lines (because of the global variable). I know that it's not the smartest or cleanest, but how can I make this into a two liner? I don't know how I could use two fors in one list comprehension.
def get_ngrams(n_gram=4):
global text
n_grams = []
for word in text.split():
n_grams += [word[i: i + 4]
for i in range(len(word)) if len(word) >= 4 and len(word[i: i + 4]) >= 4]
return n_grams