组合数据类型练习,英文词频统计实例上
1.
d={'林彬':'01','卢本伟':'03','pdd':'03'}
print(d['林彬'])
d.pop('pdd')
print(d)
print(d.items())
d['ty']='12'
print(d)
2.
ls=list('123456')
print(ls)
for i in ls:
print(i)
tu=tuple('123456')
print(tu)
for i in tu:
print(i)
x=list('123456')
y=tuple('abcdef')
z=dict(zip(y,x))
print(z)
for i in z:
print(i,z[i])
jihe=set('456')
print(jihe)
for i in jihe:
print(i)
元组和列表十分类似,只不过元组和字符串一样是不可变的,即你不能修改元组。元组是任意对象的有序集合,数组的同性。
列表是任意对象的有序集合;可通过偏移存取,注意,列表中的元素都是可变的,这是不同于元组的。
在字典里,不能再有序列操作,虽然字典在某些方面与列表类似,但不要把列表套在字典上。
集合才能做并、交集的运算。
3.
news='''We don't talk anymore
We don't talk anymore
We don't talk anymore
Like we used to do
We don't laugh anymore
What was all of it for ?
We don't talk anymore
Like we used to do
I just heard you ( ya ) found the one you'vebeen lookin'
You been looking for
I wish i would've konwn that wasn't me
Cause even after all this time i still wonder
Why i can't move on ?
Just the way you dance so easliy
Don't wanna know
The kinda (kind of) dress you're wearin' tonight
If he's holdin' onto you so tight
The way i did before
I overdosed
Should've known your love was game
Now I can't get'cha outof my brain
Ooh it's such a shame
We don't talk anymore
We don't talk anymore
We don't talk anymore
Like we used to do
We don't laugh anymore
What was all of it for ?
We don't talk anymore
Like we used to do
Selena : I just hope you'r lyin' next to somebody
Know it's hard to love yalike me
Must be a good reason that you're gone
Every now and then
I think you might want me to come show up yourdoor
But I'm just too afraidthat i'll be worng
Don't wanna know
If you'ra lookin' intoher eyes
If she's holdin' onto youso tight
The way i did before
I overdosed
Should've know your lovewas a game
Now I can't get'cha outof my brain
Ooh it's such a shame
We don't talk anymore
We don't talk anymore
We don't talk anymore
Like we used to do
We don't laugh anymore
What was all of it for ?
We don't talk anymore
Like we used to do
Charlie: Like we used to do
Don't wanna know
The kinda dress you'rewearin' tonight
If he's givin' it to youjust right
The way i did before
S: I overdosed
Should've know your lovewas a game
Now I can't get'cha outof my brain
Charlie: Ooh it's such a shame
We don't talk anymore
We don't talk anymore
We don't talk anymore
Like we used to do
We don't laugh anymore
What was all of it for ?
We don't talk anymore
Like we used to do
We don't talk anymore
The way i did before
We don't talk anymore
Ooh Woo S: Ooh it's such a shame
Chalie: We don't talk anymore '''
news=news.lower()
for i in ',.?\n()"':
news=news.replace(i,' ')
word=news
word=word.split(' ')
word.sort()
zd=set(word)
di={}
for i in zd:
di[i]=word.count(i)
print(i,di[i])