Model s.str.split().str.join(" ").str.title() and count how many distinct names remain.
What to build
A program that normalises names and counts the distinct ones.
Requirements
- For each name: remove spaces at both ends, reduce every run of spaces inside to one space, and convert to title case.
- Print each cleaned name on its own line, in order, then
unique N, the number of distinct cleaned names.
Input
Line 1: n. Then n names, one per line.
Output
n + 1 lines.
Constraints
1 ≤ n ≤ 1000; every name has at least one letter.
Example
Input:
3
ana smith
ANA SMITH
Ben Lee
Output:
Ana Smith
Ana Smith
Ben Lee
unique 2
Why it works
Two spellings of the same name only compare equal once they share one standard form, so cleaning comes before counting distinct values.
Examples
Example 1 · Input
3 ana smith ANA SMITH Ben Lee
Expected output
Ana Smith Ana Smith Ben Lee unique 2
Example 2 · Input
1 x
Expected output
X unique 1
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
" ".join(name.split()) trims the ends and collapses inner spaces.
Hint 2
Then apply title() and count distinct results with a set.
Solution
Show one correct solution (try it yourself first)
n = int(input())
names = [" ".join(input().split()).title() for _ in range(n)]
for name in names:
print(name)
print("unique", len(set(names)))