Unique Words Count
Python
Easy
3 views
Problem Description
A line sentence is provided. Words are separated by spaces. Count how many unique words are there and output the count.
Input Format
One line sentence.
Output Format
One integer uniqueCount.
Constraints
Total characters
Official Solution
import sys
s=sys.stdin.read()
if s is None: sys.exit(0)
if s.endswith('\
'):
s=s[:-1]
words=[w for w in s.split(' ') if w!='']
seen={}
for w in words:
seen[w]=1
sys.stdout.write(str(len(seen)))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!