# coding: utf-8
#création d'une méthode qui détermine la liste des mots communs en T1 et T2
def commonWords(T1 , T2):
# # convertir les textes en listes
listWords_in_T1 = T1.split()
listWords_in_T2 = T2.split()
# initialisation de la liste des mots communs
listCommon_words = []
for word in listWords_in_T1 :
if word in listWords_in_T2 and word not in listCommon_words:
listCommon_words.append(word)
return listCommon_words
# Création d'une méthode qui détermine le mot commun avec une longueur maximale
def commonMax(T1, T2):
listCommon_words = commonWords(T1 , T2)
# intitialisation de la longueur maximale
maxLength = 0
for word in listCommon_words:
if len(word) >= maxLength:
maxLength = len(word)
# recherche des mots communs de longueurs maximales
listCommonWordMax = []
for word in listCommon_words:
if len(word) == maxLength:
listCommonWordMax.append(word)
return listCommonWordMax
T1 = "Python created by Guidorossum is open source programming language. Python was created on 1991"
T2 = "Python created by Guidorossum is the most popular programming language Guidorossum"
print(commonMax(T1 , T2))
# La sortie est: ['Guidorossum', 'programming']
1 thought on “Solution Exercice 91: liste des mots de longueurs maximales communs à deux chaines texte python”