
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python program to remove all duplicates word from a given sentence.
Given a sentence. Remove all duplicates words from a given sentence.
Example
Input: I am a peaceful soul and blissful soul. Output: I am a peaceful soul and blissful.
Algorithm
Step 1: Split input sentence separated by space into words. Step 2: So to get all those strings together first we will join each string in a given list of strings. Step 3: now create a dictionary using the counter method which will have strings as key and their Frequencies as value. Step 4: Join each words are unique to form single string.
Example Code
from collections import Counter def remov_duplicates(st): st = st.split(" ") for i in range(0, len(st)): st[i] = "".join(st[i]) dupli = Counter(st) s = " ".join(dupli.keys()) print ("After removing the sentence is ::>",s) # Driver program if __name__ == "__main__": st = input("Enter the sentence") remov_duplicates(st)
Output
Enter the sentence ::> i am a peaceful soul and blissful soul After removing the sentence is ::> i am a peaceful soul and blissful
- Related Articles
- C# program to remove all duplicates words from a given sentence
- Java program to remove all duplicates words from a given sentence
- Remove all duplicates from a given string in Python
- Remove all duplicates from a given string in C#
- Python program to remove Duplicates elements from a List?
- Python program to reverse each word in a sentence?
- Python Program to replace a word with asterisks in a sentence
- Java program to remove duplicates elements from a List
- Python - Ways to remove duplicates from list
- Write a program in C++ to remove duplicates from a given array of prime numbers
- Golang Program To Remove Duplicates From An Array
- Java program to count the characters in each word in a given sentence
- Python Program to Replace all words except the given word
- Remove All Adjacent Duplicates In String in Python
- Python Program to Remove all digits before given Number

Advertisements