Count Unique Words
Count Unique Words - WIPRO
Problem:
The program must accept a string S containing multiple words as the input. The program must print the number of unique words (i.e., the words that are not repeated) present in the string S as the output.
Boundary Condition(s):
1 <= Length of S <= 1000
Input Format:
The first line contains S.
Output Format:
The first line contains the number of unique words present in the string S.
Example Input/Output 1:
Input:
I love to code and I like to participate in coding competitions
Output:
8
Explanation:
The 8 unique words are given below. love code and like participate in coding competitions
Example Input/Output 2:
Input:
Go Back Welcome back
Output:
4
Program:
s = input().strip().split()
count = 0
for i in set(s):
if s.count(i) == 1:
count += 1
print(count)
Comments
Post a Comment