Delete common elements from two lines of Strings in Python

Rafsan Jany
Sep 4, 2018 · 1 min read

Let,
We have two strings
s1 = “She is a good girl”
s2 = “He is a good boy”

We need to delete the common words from these two strings. Let’s do it:

s1 = raw_input(“Enter line: ”).split()
s2 = raw_input(“Enter line: ”).split()

for i in s1[:]:
….if i in s2:
……..s1.remove(i)
……..s2.remove(i)

print “ ”.join(s1) #output: She girl
print “ ”.join(s2) #output: He boy

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade