Trigrams are a special case of the n-gram, where n is 3. One trigram is a continious sequence of 3 chars in phrase. [Wikipedia](https://en.wikipedia.org/wiki/Trigram)

 - return all trigrams for the given phrase 
 - replace spaces with \_ 
 - return an empty string for phrases shorter than 3

Example:

trigrams('the quick red') ==  the he\_ e\_q \_qu qui uic ick ck\_ k\_r \_re red

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def trigrams(phrase):
	

Solutions:
def trigrams(phrase):
	phrase = phrase.replace(' ', '_')
	return ' '.join([phrase[i:i + 3] for i in range(len(phrase) - 2)])


def trigrams(phrase):
	solution = ''
	if len(phrase) < 3:
		return solution
	phrase = phrase.replace(' ', '_')
	for i in range(len(phrase) - 2):
		solution = solution + ' ' + phrase[i:i + 3]
	return solution[1:]


def trigrams(phrase):
	phrase = phrase.replace(' ', '_')
	return ' '.join((''.join(xs) for xs in zip(phrase, phrase[1:], phrase[2:])))


def trigrams(p):
	r = ''
	for i in range(len(p) - 2):
		r += p[i:i + 3].replace(' ', '_') + ' '
	return r.strip()


def trigrams(s):
	return ' '.join([''.join(w).replace(' ', '_') for w in list(zip(s, s[1:], s[2:]))]) if len(s) > 2 else ''


def trigrams(phrase):
	if len(phrase) < 3:
		return ''
	phrase = phrase.replace(' ', '_')
	chars = [x for x in phrase]
	trigram = []
	for x in range(1, len(chars) - 1):
		trigram.append(chars[x - 1] + chars[x] + chars[x + 1])
	return ' '.join(trigram)


def trigrams(phrase):
	svar = ''
	if len(phrase) < 3:
		return ''
	else:
		phrase = phrase.replace(' ', '_')
		for i in range(len(phrase) - 2):
			svar = svar + ' ' + phrase[i:i + 3]
		return svar[1:]


def trigrams(phrase):
	if len(phrase) < 3:
		return ''
	phrase = phrase.replace(' ', '_')
	ret = []
	for i in range(len(phrase) - 2):
		ret.append(phrase[i:i + 3])
	return ' '.join(ret)