Exercise 80
Write a python algorithm which determines the list of all common words to two text T1 and T2 without repetition.
Example if: T1 = "Python is open source programming language created on 1991" and T2 = "Python is the most popular programming language", the algorithm returns the liste:
['Python', 'is', 'programming', 'language']
Solution
def common_words_without_repetition(T1, T2):
# Convert the texts to lowercase and split into words
words_T1 = set(T1.lower().split())
words_T2 = set(T2.lower().split())
# Find the common words without repetition
common_words = list(words_T1.intersection(words_T2))
return common_words
# Example usage:
T1 = "Python is open source programming language created on 1991"
T2 = "Python is the most popular programming language"
result = common_words_without_repetition(T1, T2)
print(result)
# Output : ['programming', 'language', 'is', 'python']
Younes Derfoufi
CRMEF OUJDA
[…] Exercise 78** || Solution […]