Write a Python program to find the words that appear in both strings, ignoring punctuation.
Input
"Very Good Morning, How are You" and "You are a Good student, keep it up"
Output
['Good', 'You', 'are']
Approach
Strip punctuation, split into sets, and intersect.
Solution
Python
s1="Very Good Morning, How are You"s2="You are a Good student, keep it up"w1={w.strip(",.")forwins1.split()}w2={w.strip(",.")forwins2.split()}print(sorted(w1&w2))
Output
['Good', 'You', 'are']
Line by line
Lines 3-4
strip(",.") removes punctuation stuck to a word, such as “Morning,”.
Line 5
& keeps the words present in both sets.
Learn the concept
New to this topic? Read the lesson, then come back.