Given a sentence containing n words/strings. Remove all duplicates words/strings which are similar to each others.
Input : Geeks for Geeks Output : Geeks for Input : Python is great and Java is also great Output : is also Java Python and great
We can solve this problem quickly using python Counter() method. Approach is very simple.
1) Split input sentence separated by space into words.
2) So to get all those strings together first we will join each string in given list of strings.
3) Now create a dictionary using Counter method having strings as keys and their frequencies as values.
4) Join each words are unique to form single string.
is also Java Python and great
Output:- Python is great and java also
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.