## Monday, November 2, 2020

Solution Exercise 80: python program that determines the list of common words in given two texts #### Exercice 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. Python was created on 1991"
and
T2 = "Python is the most popular programming language "
, the algorithm returns the liste
``['Python', 'is', 'programming', 'language.']``
( the word 'Python' must be added only once even if it shared twice)

#### Solution

``````def commonWords(T1 , T2):
# converting the texts into lists
listWords_in_T1 = T1.split()
listWords_in_T2 = T2.split()
print(listWords_in_T2)

# initializing the common words
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

# Example
T1 = "Python is open source programming language. Python was created on 1991"
T2 = "Python is the most popular programming language. "
print("The list of common words is : " , commonWords(T1 , T2))
# The output is :
# The list of common words is :  ['Python', 'is', 'programming', 'language.']``````

Younes Derfoufi
my-courses.net

## Python Exercises With Solutions

1. Python Arithmetic Exercises
2. Equations & System Of Equations
3. Polynomials and Functions
4. Python Arithmetic Exercises
5. Numpy, Matplolib, Sympy , Scipy - Exercises
6. Python Arithmetic Exercises

Younes Derfoufi

## Sample Text 