A character trigram is a group of three consecutive characters as they appear in a word. For example, the word "hello" contains the trigrams "hel", "ell", and "llo".
Write a function that receives a word and returns a list of its character trigrams.
>>> trigrams('hello')
['hel', 'ell', 'llo']
>>> trigrams('crocodile')
['cro', 'roc', 'oco', 'cod', 'odi', 'dil', 'ile']
>>> trigrams('hi')
[]Write a program that reads a sequence of words and prints the
pairs of consecutive words in the sequence that have at least one
trigram in common. The program must use the trigrams
function defined above.
Hint: It may be useful to define another function that checks whether two lists of trigrams have at least a common element
The input is a sequence of words, all of them contain only lowercase letters.
The output is a list of word pairs that are consecutive in the input sequence and have some common trigram.
Author: ProAl
Generation: 2026-01-25T16:00:51.159Z
© Jutge.org, 2006–2026.
https://jutge.org