Solve problem "The number of distinct words in some text" online - Learn Python 3 - Snakify

Problem «The number of distinct words in some text» (Medium)


Statement

Given a number \( n \), followed by \( n \) lines of text, print the number of distinct words that appear in the text.

For this, we define a word to be a sequence of non-whitespace characters, seperated by one or more whitespace or newline characters. Punctuation marks are part of a word, in this definition.


In all the problems input the data using input() and print the result using print().



Saved solutions

Tests

Input Correct answer Result
4
She sells sea shells on the sea shore;
The shells that she sells are sea shells I'm sure.
So if she sells sea shells on the sea shore,
I'm sure that the shells are sea shore shells.
19
14
The other two, slight air, and purging fire,
Are both with thee, wherever I abide,
The first my thought, the other my desire,
These present-absent with swift motion slide.
For when these quicker elements are gone
In tender embassy of love to thee,
My life being made of four, with two alone,
Sinks down to death, oppressed with melancholy.
Until life's composition be recured,
By those swift messengers returned from thee,
Who even but now come back again assured,
Of thy fair health, recounting it to me.
This told, I joy, but then no longer glad,
I send them back again and straight grow sad.
87
1
a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
1
1
a b a c a b a d a b a c a b a
4
30
Not much chance, completely cut loose from purpose,
He was a young man riding a bus through North Carolina on the way to somewhere.
And it began to snow.
And the bus stopped at a little cafe in the hills and the passengers entered.
And he sat at the counter with the others, and he ordered, the food arrived.
And the meal was particularly good.
And the coffee.
The waitress was unlike the women he had known.
She was unaffected, and there was a natural humor which came from her.
And the fry cook said crazy things.
And the dishwasher in back laughed a good clean pleasant laugh.
And the young man watched the snow through the window.
And he wanted to stay in that cafe forever.
The curious feeling swam through him that everything was beautiful there.
And it would always stay beautiful there.
And then the bus driver told the passengers that it was time to board.
And the young man thought: “I’ll just stay here, I’ll just stay here.”
And then he rose and he followed the others into the bus.
He found his seat and looked at the cafe through the window.
And then the bus moved off, down a curve, downward, out of the hills.
And the young man looked straight forward.
And he heard the other passengers speaking of other things,
or they were reading or trying to sleep.
And they hadn’t noticed the magic.
And the young man put his head to one side,
closed his eyes, and pretended to sleep.
There was nothing else to do,
just to listen to the sound of the engine,
and the sound of the tires
in the snow.
148