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.
- Python | Check if given words appear together in a list of sentence
- Find most similar sentence in the file to the input sentence | NLP
- Remove all duplicates from a given string in Python
- Python | Sort words of sentence in ascending order
- Python program to count words in a sentence
- Python | Spilt a sentence into list of words
- Python groupby method to remove all consecutive duplicates
- Python | Remove all duplicates and permutations in nested list
- NLP | How tokenizing text, sentence, words works
- Python | Sort given list by frequency and remove duplicates
- Python Remove Duplicates from a List
- Python - Ways to remove duplicates from list
- Python | Remove consecutive duplicates from list
- Python | Remove duplicates from nested list
- Python | Remove duplicates in Matrix
- Python | Remove duplicates based on Kth element tuple list
- Python - Remove Equilength and Equisum Tuple Duplicates
- Python - Remove Kth Index Duplicates in Tuple
- Python - Remove alternate consecutive duplicates
- Python - Remove K length Duplicates from String
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Divyu_Pandey