Table of Contents
Introduction
In this section of programming, we will find and print the uncommon words from two given strings.
Program
def uncomn_wrd(x,y): x = x.split() y = y.split() # Using symmetric_difference() k = set(x).symmetric_difference(set(y)) return k str1 = input("Enter first string : ") str2 = input("Enter second string : ") print("Uncommon words are :", list(uncomn_wrd(str1, str2)))
Output
Explanation
In general, to find the uncommon words we can make a hash table of words as key and print out the words that occurs exactly once.
In our coding we have used a python in-built function symmetric_difference() which will list out the set of words from both the input strings except the common one’s.
0 Comments