In this program, we will take two strings as input and get common words from strings.
Steps to solve the program
- Take two strings as input and create an empty list.
- Using For loop find the common words from strings and add them to the empty list.
- Convert the list into a string Join().
- Print the output.
#Input strings
string1 = "Very Good Morning, How are You"
string2 = "You are a Good student, keep it up"
List = []
for word in string1.split(" "):
if word in string2.split(" "):
List.append(word)
#Printing output
" ".join(List)
Output :
'Good are You'