组合数据类型,英文词频统计

本文通过一个Python脚本示例,展示了如何进行列表和集合的基本操作,包括插入元素、追加元素、去除重复项、集合交并差运算等,为初学者提供了实践指导。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

classmates = ['Michael', 'Bob', 'Tracy','李三' ,'Tracy',56]
new =['Rose','Jack']
classmates.insert(2,'Tom')
classmates.append('Jack')
classmates.extend(new)
classmates.pop(1)
print(classmates)

s={1,2,3}
s.add(4)
s.remove(4)
s=set([1,1,2,2,3,3])
print(s)
s1=set([1,2,3])
s2=set([3,4,5])
print(s1&s2)
print(s1|s2)
print(s2-s1)

classmates=['Michael','Bob','Tracy']
scores=[95,75,85]
d={'Bob':75,'Michael':95,'Tracy':85}
len(d)
d['Rose']=88
d.pop('Bob')
print(d)


strbig='''Well I wonder could it be
  When I was dreaming about you baby
  You were dreaming of me
  Call me crazy
  Call me blind
  To still be suffering is stupid after all of this time

  Did I lose my love to someone better
  And does she love you like I do
  I do, you know I really really do

  Well hey
  So much I need to say
  Been lonely since the day
  The day you went away

  So sad but true
  For me there's only you
  Been crying since the day
  the day you went away

  I remember date and time
  September twenty second
  Sunday twenty five after nine
  In the doorway with your case
  No longer shouting at each other
  There were tears on our faces

  And we were letting go of something special
  Something we'll never have again
  I know, I guess I really really know

  Why do we never know what we've got till it's gone
  How could I carry on the day you went away
  Cause I've been missing you so much I have to say

  just one last dance
  
  Written by: Rob Tyger & Kay Denar

  Just one last dance ...oh baby...
  just one last dance

  We meet in the night in the Spanish caf?
  I look in your eyes just don't know
  what to say
  It feels like I'm drowning in salty water
  A few hours left till the sun's gonna rise
  tomorrow will come an it's time to realize
  our love has finished forever

  how I wish to come with you
  (wish to come with you)
  how I wish we make it through

  (Chorus)
  Just one last dance
  before we say goodbye
  when we sway and turn round and
  round and round
  it's like the first time
  Just one more chance
  hold me tight and keep me warm
  cause the night is getting cold
  and I don't know where I belong
  Just one last dance

  The wine and the lights and the
  Spanish guitar
  I'll never forget how romantic
  they are
  but I know, tomorrow I'll lose
  the one I love

  There's no way to come with you
  it's the only thing to do
'''

strList =strbig.split()
print(strList)

strSet=set(strList)

for word in strSet:
    print(word,strList.count(word))
C:\Users\Administrator\AppData\Local\Programs\Python\Python36\python.exe C:/Users/Administrator/PycharmProjects/untitled1/text1.py
['Michael', 'Tom', 'Tracy', '李三', 'Tracy', 56, 'Jack', 'Rose', 'Jack']
{1, 2, 3}
{3}
{1, 2, 3, 4, 5}
{4, 5}
{'Michael': 95, 'Tracy': 85, 'Rose': 88}
['Well', 'I', 'wonder', 'could', 'it', 'be', 'When', 'I', 'was', 'dreaming', 'about', 'you', 'baby', 'You', 'were', 'dreaming', 'of', 'me', 'Call', 'me', 'crazy', 'Call', 'me', 'blind', 'To', 'still', 'be', 'suffering', 'is', 'stupid', 'after', 'all', 'of', 'this', 'time', 'Did', 'I', 'lose', 'my', 'love', 'to', 'someone', 'better', 'And', 'does', 'she', 'love', 'you', 'like', 'I', 'do', 'I', 'do,', 'you', 'know', 'I', 'really', 'really', 'do', 'Well', 'hey', 'So', 'much', 'I', 'need', 'to', 'say', 'Been', 'lonely', 'since', 'the', 'day', 'The', 'day', 'you', 'went', 'away', 'So', 'sad', 'but', 'true', 'For', 'me', "there's", 'only', 'you', 'Been', 'crying', 'since', 'the', 'day', 'the', 'day', 'you', 'went', 'away', 'I', 'remember', 'date', 'and', 'time', 'September', 'twenty', 'second', 'Sunday', 'twenty', 'five', 'after', 'nine', 'In', 'the', 'doorway', 'with', 'your', 'case', 'No', 'longer', 'shouting', 'at', 'each', 'other', 'There', 'were', 'tears', 'on', 'our', 'faces', 'And', 'we', 'were', 'letting', 'go', 'of', 'something', 'special', 'Something', "we'll", 'never', 'have', 'again', 'I', 'know,', 'I', 'guess', 'I', 'really', 'really', 'know', 'Why', 'do', 'we', 'never', 'know', 'what', "we've", 'got', 'till', "it's", 'gone', 'How', 'could', 'I', 'carry', 'on', 'the', 'day', 'you', 'went', 'away', 'Cause', "I've", 'been', 'missing', 'you', 'so', 'much', 'I', 'have', 'to', 'say', 'just', 'one', 'last', 'dance', 'Written', 'by:', 'Rob', 'Tyger', '&', 'Kay', 'Denar', 'Just', 'one', 'last', 'dance', '...oh', 'baby...', 'just', 'one', 'last', 'dance', 'We', 'meet', 'in', 'the', 'night', 'in', 'the', 'Spanish', 'caf?', 'I', 'look', 'in', 'your', 'eyes', 'just', "don't", 'know', 'what', 'to', 'say', 'It', 'feels', 'like', "I'm", 'drowning', 'in', 'salty', 'water', 'A', 'few', 'hours', 'left', 'till', 'the', "sun's", 'gonna', 'rise', 'tomorrow', 'will', 'come', 'an', "it's", 'time', 'to', 'realize', 'our', 'love', 'has', 'finished', 'forever', 'how', 'I', 'wish', 'to', 'come', 'with', 'you', '(wish', 'to', 'come', 'with', 'you)', 'how', 'I', 'wish', 'we', 'make', 'it', 'through', '(Chorus)', 'Just', 'one', 'last', 'dance', 'before', 'we', 'say', 'goodbye', 'when', 'we', 'sway', 'and', 'turn', 'round', 'and', 'round', 'and', 'round', "it's", 'like', 'the', 'first', 'time', 'Just', 'one', 'more', 'chance', 'hold', 'me', 'tight', 'and', 'keep', 'me', 'warm', 'cause', 'the', 'night', 'is', 'getting', 'cold', 'and', 'I', "don't", 'know', 'where', 'I', 'belong', 'Just', 'one', 'last', 'dance', 'The', 'wine', 'and', 'the', 'lights', 'and', 'the', 'Spanish', 'guitar', "I'll", 'never', 'forget', 'how', 'romantic', 'they', 'are', 'but', 'I', 'know,', 'tomorrow', "I'll", 'lose', 'the', 'one', 'I', 'love', "There's", 'no', 'way', 'to', 'come', 'with', 'you', "it's", 'the', 'only', 'thing', 'to', 'do']
meet 1
How 1
You 1
lose 2
could 2
sun's 1
much 2
salty 1
turn 1
Cause 1
So 2
gonna 1
Been 2
guitar 1
all 1
nine 1
belong 1
make 1
were 3
just 3
I'm 1
Just 4
Denar 1
Well 2
gone 1
do, 1
tight 1
need 1
an 1
case 1
realize 1
finished 1
We 1
love 4
first 1
There's 1
guess 1
thing 1
know, 2
second 1
& 1
Spanish 2
Call 2
someone 1
Did 1
date 1
by: 1
really 4
last 5
rise 1
with 4
away 3
at 1
cause 1
what 2
got 1
getting 1
other 1
September 1
are 1
Kay 1
we'll 1
still 1
There 1
(wish 1
our 2
special 1
caf? 1
tears 1
For 1
remember 1
doorway 1
better 1
she 1
we 5
something 1
about 1
shouting 1
was 1
Written 1
will 1
The 2
been 1
dance 5
feels 1
round 3
true 1
Why 1
forever 1
went 3
five 1
my 1
there's 1
this 1
And 2
like 3
day 5
don't 2
each 1
wish 2
only 2
through 1
time 4
Rob 1
sway 1
letting 1
more 1
dreaming 2
go 1
crying 1
till 2
lights 1
sad 1
the 14
warm 1
is 2
on 2
in 4
No 1
carry 1
eyes 1
wine 1
where 1
To 1
A 1
know 5
baby... 1
you 10
blind 1
look 1
I'll 2
we've 1
and 8
longer 1
one 7
Tyger 1
your 2
say 4
It 1
again 1
how 3
lonely 1
hold 1
hey 1
night 2
(Chorus) 1
be 2
twenty 2
come 4
it 2
wonder 1
water 1
drowning 1
before 1
but 2
chance 1
cold 1
they 1
suffering 1
Something 1
after 2
romantic 1
faces 1
to 9
few 1
keep 1
of 3
it's 4
does 1
...oh 1
so 1
has 1
hours 1
tomorrow 2
never 3
missing 1
when 1
stupid 1
I've 1
me 6
goodbye 1
do 4
way 1
I 20
you) 1
no 1
crazy 1
forget 1
In 1
left 1
have 2
When 1
baby 1
Sunday 1
since 2

Process finished with exit code 0

 

转载于:https://www.cnblogs.com/aaaadaztz/p/9679927.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值