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.
Write a Python program to get all the numbers from a multi-line string.
Input
a paragraph containing 1112, 1773, 444, 5324 and 555
Output
[1112, 1773, 444, 5324, 555]
Approach
Use re.findall(r"\d+", text) and convert each match to int.
Solution
Python
importretext="""Sinak's 1112 aim is to 1773 create a new generation of people whounderstand 444 that an organization's 5324 success or failure isbased on 555 leadership excellence and not managerial acumen"""numbers=[int(n)forninre.findall(r"\d+",text)]print(numbers)
Output
[1112, 1773, 444, 5324, 555]
Line by line
Line 6
\d+ matches each run of digits; the list comprehension converts them to integers.
Note
The original sample output listed 5324 twice and missed 444; the real numbers in the text are shown here.
Learn the concept
New to this topic? Read the lesson, then come back.