Unique Words Count (Case-Insensitive)
Python
Medium
7 views
Problem Description
For each testcase you get a full line sentence. Count unique words ignoring case and output the count.
Input Format
First line t. Next t lines are sentences.
Output Format
t lines counts.
Sample Test Case
Input:
3
Hello hello world
A b A c
Constraints
Total characters
Official Solution
import sys
lines=sys.stdin.read().splitlines()
if not lines:
sys.exit(0)
try:
t=int(lines[0].strip())
except Exception:
t=0
idx=1
out=[]
for _ in range(t):
s=lines[idx] if idx<len(lines) else ''
idx+=1
words=[w.lower() for w in s.split()]
out.append(str(len(set(words))))
sys.stdout.write('\
'.join(out))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!