here is 3 line code
# python program to find uncommon words from two strings
string1 = "hello world in python"
string2 = "hello world in java"
print(set(string1.split()) ^ set(string2.split()))
>>>
>>> x = "hello world in python"
>>> y = "hello world in java"
>>> print(set(x.split()) - set(y.split()), set(y.split()) - set(x.split()))
{'python'} {'java'}
>>>
Using Symmetric Differentiation
>>>
>>> x = "hello world in python"
>>> y = "hello world in java"
>>> xset = set(x.split())
>>> yset = set(y.split())
>>> xset ^ yset
{'java', 'python'}
>>>
>>>
0 Comments