1
Be the text below:
This is the most favourable period for travelling in Russia. They fly
quickly over the snow in their sledges; the motion is pleasant, and,
in my opinion, far more agreeable than that of an English stagecoach.
The cold is not excessive, if you are wrapped in furs--a dress which
I have already adopted, for there is a great difference between walking
the deck and remaining seated motionless for hours, when no exercise
prevents the blood from actually freezing in your veins. I have no
ambition to lose my life on the post-road between St. Petersburgh
and Archangel. I shall depart for the latter town in a fortnight
or three weeks; and my intention is to hire a ship there, which can
easily be done by paying the insurance for the owner, and to engage
as many sailors as I think necessary among those who are accustomed
to the whale-fishing. I do not intend to sail until the month of June;
and when shall I return? Ah, dear sister, how can I answer this question?
If I succeed, many, many months, perhaps years, will pass before you
and I may meet. If I fail, you will see me again soon, or never.
Farewell, my dear, excellent Margaret. Heaven shower down blessings
on you, and save me, that I may again and again testify my gratitude
for all your love and kindness.
I would like to create a list of words from the text and display the frequency of each one. I found on the Internet the code below that works but did not understand:
def PegaPalavras(texto):
return ''.join((c if c.isalnum() else ' ') for c in texto).split()
I tried to rewrite it more simply but I couldn’t:
def PegaPalavras(texto):
palavras = []
for c in texto:
if c.isalnum():
c=c
palavras.append("".join(c).split())
else:
c =" "
palavras.append("".join(c).split())
return palavras
How to rewrite the first code more explicitly (without just one line), in order to facilitate its understanding? Some other solution?
Thank you! I could explain the code -> Return ''. Join((c if c.isalnum() Else ' ') for c in text). split()
– Ed S
your code does not ignore the score...
– Ed S
I haven’t been able to get a look at that code yet..
– Vinicius Bussola