Find uncommon words from two string
We will take two strings as input from users consisting of words. And then we will print all words from the string that are not present in both the strings.
The string consists of sentences that are space-separated words.
Example:
Input:
str1 = "learn programming at includehelp"
str2 = "learn python programming language"
Output:
"python", "at", "includehelp"
A simple method to solve the problem is by finding words that occur only once in any of the strings.
Program to find uncommon words from two string
Output:
Alternate method
Another way to solve the problem is by storing both the strings as lists and then store the characters from one list that are not present in another to a list. Then print all values that are uncommon for both the strings.
Program to find uncommon words from two string,
Output:
Method 2: Using built-in Python function
Python provides a built-in function to perform this task. It is symmetric_difference() on sets.
Program to find uncommon words from two strings
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer