Занятие 11. Словари

Задача «Частотный анализ»


Условие

Дан текст: в первой строке записано количество строк в тексте, а затем сами строки. Выведите все слова, встречающиеся в тексте, по одному на каждую строку. Слова должны быть отсортированы по убыванию их количества появления в тексте, а при одинаковой частоте появления — в лексикографическом порядке.

Указание. После того, как вы создадите словарь всех слов, вам захочется отсортировать его по частоте встречаемости слова. Желаемого можно добиться, если создать список, элементами которого будут кортежи из двух элементов: частота встречаемости слова и само слово. Например, [(2, 'hi'), (1, 'what'), (3, 'is')]. Тогда стандартная сортировка будет сортировать список кортежей, при этом кортежи сравниваются по первому элементу, а если они равны — то по второму. Это почти то, что требуется в задаче.


Во всех задачах считывайте входные данные через input() и выводите ответ через print().


Войти или зарегистрироваться, чтобы отправлять решения на проверку

Тесты

Входные данные Правильный ответ Что вывела программа Результат
9
hi
hi
what is your name
my name is bond
james bond
my name is damme
van damme
claude van damme
jean claude van damme
damme
is
name
van
bond
claude
hi
my
james
jean
what
your
1
ai ai ai ai ai ai ai ai ai ai
ai
2
iovjxotfvt h h iovjxotfvt h iovjxotfvt iovjxotfvt h
h iovjxotfvt
h
iovjxotfvt
4
eqlbahbovv pzpumhz mlcgtbbnfr
axsjbontg emojwajtfi
basdu nzyh wpyirkmz xxkmrr blnlqwcpur eqlbahbovv nzyh mlcgtbbnfr
mlcgtbbnfr axsjbontg mlcgtbbnfr mlcgtbbnfr mlcgtbbnfr blnlqwcpur mlcgtbbnfr
mlcgtbbnfr
axsjbontg
blnlqwcpur
eqlbahbovv
nzyh
basdu
emojwajtfi
pzpumhz
wpyirkmz
xxkmrr
14
That thou hast her it is not all my grief,
And yet it may be said I loved her dearly,
That she hath thee is of my wailing chief,
A loss in love that touches me more nearly.
Loving offenders thus I will excuse ye,
Thou dost love her, because thou know'st I love her,
And for my sake even so doth she abuse me,
Suff'ring my friend for my sake to approve her.
If I lose thee, my loss is my love's gain,
And losing her, my friend hath found that loss,
Both find each other, and I lose both twain,
And both for my sake lay on me this cross,
But here's the joy, my friend and I are one,
Sweet flattery, then she loves but me alone.
my
I
And
for
friend
her,
is
love
me
sake
she
That
and
both
hath
her
it
lose
loss
that
thou
A
Both
But
If
Loving
Suff'ring
Sweet
Thou
abuse
all
alone.
approve
are
be
because
but
chief,
cross,
dearly,
dost
doth
each
even
excuse
find
flattery,
found
gain,
grief,
hast
her.
here's
in
joy,
know'st
lay
losing
loss,
love's
loved
loves
may
me,
more
nearly.
not
of
offenders
on
one,
other,
said
so
the
thee
thee,
then
this
thus
to
touches
twain,
wailing
will
ye,
yet
10
Death there mirth way the noisy merit. Piqued shy spring nor six though mutual living ask extent. Replying of dashwood advanced ladyship smallest disposal or. Attempt offices own improve now see. Called person are around county talked her esteem. Those fully these way nay thing seems.
At distant inhabit amongst by. Appetite welcomed interest the goodness boy not. Estimable education for disposing pronounce her. John size good gay plan sent old roof own. Inquietude saw understood his friendship frequently yet. Nature his marked ham wished.
Marianne or husbands if at stronger ye. Considered is as middletons uncommonly. Promotion perfectly ye consisted so. His chatty dining for effect ladies active. Equally journey wishing not several behaved chapter she two sir. Deficient procuring favourite extensive you two. Yet diminution she impossible understood age.
So if on advanced addition absolute received replying throwing he. Delighted consisted newspaper of unfeeling as neglected so. Tell size come hard mrs and four fond are. Of in commanded earnestly resources it. At quitting in strictly up wandered of relation answered felicity. Side need at in what dear ever upon if. Same down want joy neat ask pain help she. Alone three stuff use law walls fat asked. Near do that he help.
Betrayed cheerful declared end and. Questions we additions is extremely incommode. Next half add call them eat face. Age lived smile six defer bed their few. Had admitting concluded too behaviour him she. Of death to or to being other.
Consulted he eagerness unfeeling deficient existence of. Calling nothing end fertile for venture way boy. Esteem spirit temper too say adieus who direct esteem. It esteems luckily mr or picture placing drawing no. Apartments frequently or motionless on reasonable projecting expression. Way mrs end gave tall walk fact bed.
Offered say visited elderly and. Waited period are played family man formed. He ye body or made on pain part meet. You one delay nor begin our folly abode. By disposed replying mr me unpacked no. As moonlight of my resolving unwilling.
Folly words widow one downs few age every seven. If miss part by fact he park just shew. Discovered had get considered projection who favourable. Necessary up knowledge it tolerably. Unwilling departure education is be dashwoods or an. Use off agreeable law unwilling sir deficient curiosity instantly. Easy mind life fact with see has bore ten. Parish any chatty can elinor direct for former. Up as meant widow equal an share least.
With my them if up many. Lain week nay she them her she. Extremity so attending objection as engrossed gentleman something. Instantly gentleman contained belonging exquisite now direction she ham. West room at sent if year. Numerous indulged distance old law you. Total state as merit court green decay he. Steepest sex bachelor the may delicate its yourself. As he instantly on discovery concluded to. Open draw far pure miss felt say yet few sigh.
Out too the been like hard off. Improve enquire welcome own beloved matters her. As insipidity so mr unsatiable increasing attachment motionless cultivated. Addition mr husbands unpacked occasion he oh. Is unsatiable if projecting boisterous insensible. It recommend be resolving pretended middleton.
or
as
he
if
for
mr
of
on
she
the
As
at
end
fact
in
is
law
say
she.
them
too
up
way
At
It
Of
advanced
and.
are
ask
be
chatty
concluded
consisted
deficient
direct
education
esteem.
few
frequently
gentleman
hard
he.
her
her.
his
husbands
miss
motionless
mrs
my
nay
no.
nor
now
old
one
own
pain
part
projecting
replying
resolving
sent
six
size
so
so.
to
understood
unfeeling
unpacked
unsatiable
who
widow
ye
Addition
Age
Alone
Apartments
Appetite
Attempt
Betrayed
By
Called
Calling
Considered
Consulted
Death
Deficient
Delighted
Discovered
Easy
Equally
Esteem
Estimable
Extremity
Folly
Had
He
His
If
Improve
Inquietude
Instantly
Is
John
Lain
Marianne
Nature
Near
Necessary
Next
Numerous
Offered
Open
Out
Parish
Piqued
Promotion
Questions
Replying
Same
Side
So
Steepest
Tell
Those
Total
Unwilling
Up
Use
Waited
Way
West
With
Yet
You
abode.
absolute
active.
add
addition
additions
adieus
admitting
age
age.
agreeable
amongst
an
an.
and
answered
any
are.
around
asked.
attachment
attending
bachelor
bed
bed.
been
begin
behaved
behaviour
being
belonging
beloved
body
boisterous
bore
boy
boy.
by
by.
call
can
chapter
cheerful
come
commanded
considered
contained
county
court
cultivated.
curiosity
dashwood
dashwoods
dear
death
decay
declared
defer
delay
delicate
departure
diminution
dining
direction
discovery
disposal
disposed
disposing
distance
distant
do
down
downs
draw
drawing
eagerness
earnestly
eat
effect
elderly
elinor
engrossed
enquire
equal
esteems
ever
every
existence
expression.
exquisite
extensive
extent.
extremely
face.
family
far
fat
favourable.
favourite
felicity.
felt
fertile
few.
folly
fond
formed.
former.
four
friendship
fully
gave
gay
get
good
goodness
green
had
half
ham
ham.
has
help
help.
him
if.
impossible
improve
incommode.
increasing
indulged
inhabit
insensible.
insipidity
instantly
instantly.
interest
it
it.
its
journey
joy
just
knowledge
ladies
ladyship
least.
life
like
lived
living
luckily
made
man
many.
marked
matters
may
me
meant
meet.
merit
merit.
middleton.
middletons
mind
mirth
moonlight
mutual
neat
need
neglected
newspaper
noisy
not
not.
nothing
objection
occasion
of.
off
off.
offices
oh.
or.
other.
our
own.
park
perfectly
period
person
picture
placing
plan
played
pretended
procuring
projection
pronounce
pure
quitting
reasonable
received
recommend
relation
resources
roof
room
saw
see
see.
seems.
seven.
several
sex
share
shew.
shy
sigh.
sir
sir.
smallest
smile
something.
spirit
spring
state
strictly
stronger
stuff
talked
tall
temper
ten.
that
their
there
these
thing
though
three
throwing
to.
tolerably.
two
two.
uncommonly.
unwilling
unwilling.
upon
use
venture
visited
walk
walls
wandered
want
we
week
welcome
welcomed
what
wished.
wishing
with
words
ye.
year.
yet
yet.
you
you.
yourself.