码迷,mamicode.com
首页 > 其他好文 > 详细

组合数据练习,英语词频统计实例上

时间:2017-09-22 22:28:50      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:not   不可变   from   replace   使用   9.png   rust   img   play   

1

>>> d={‘01‘:95,‘02‘:92,‘03‘:86,‘04‘:70}
>>> print(d)
{‘01‘: 95, ‘02‘: 92, ‘03‘: 86, ‘04‘: 70}
>>> d[‘05‘]=80
>>> print(d)
{‘01‘: 95, ‘02‘: 92, ‘03‘: 86, ‘04‘: 70, ‘05‘: 80}
>>> d.pop(‘02‘)
92
>>> print(d)
{‘01‘: 95, ‘03‘: 86, ‘04‘: 70, ‘05‘: 80}
>>> d[‘03‘]=88
>>> print(d)
{‘01‘: 95, ‘03‘: 88, ‘04‘: 70, ‘05‘: 80}
>>> d[‘05‘]
80

2

ls=list(‘2345679900‘)
tu=tuple(‘2354687879‘)
print(ls)
print(tu)
dc=dict(zip(ls,tu))
print(dc)
print(‘ls遍历\n‘) 
for i in ls:
print(i)
print(‘tu遍历\n‘) 
for i in tu:
print(i)

print(‘dict遍历\n‘) 
for i in dc:
print(i,dc[i])

技术分享

 

3

 列表和元组是有序的,字典和集合是无序的,列表是可变的数据类型,即这种类型是可以被改变的,并且列表是可以嵌套的,列表通过中括号中用逗号分隔的项目定义。元组是不可变的。即你不能修改元组。元组通过圆括号中用逗号分隔的项目定义。元组通常用在使语句或用户定义的函数能够安全的采用一组值的时候,即被使用的元组的值不会改变。元组可以嵌套。字典通过大括号中用键值对和逗号分隔的项目定义,用空间换取时间。集合只有键没有值,可以把元组或序列中不重复的找出来,并可以做交集并集等操作

4

song=‘‘‘I don‘t like your little games
Don‘t like your tilted stage
The role you made me play of the fool
No I don‘t like you
I don‘t like your perfect crime
How you laugh when you lie
You said the gun was mine
Isn‘t cool
No I don‘t like you ooh
But I got smarter I got harder in the nick of time
Honey I rose up from the dead I do it all the time
I got a list of names and yours is in red underlined
I check it once then I check it twice ooh
Ooh look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me
Ooh look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me do
I don‘t like your kingdom keys
They once belonged to me
You asked me for a place to sleep
Locked me out and threw a feast what
The world moves on another day another drama drama
But not for me not for me all I think about is karma
And then the world moves on but one thing‘s for sure
Maybe I got mine but you‘ll all get yours
But I got smarter I got harder in the nick of time
Honey I rose up from the dead I do it all the time
I‘ve got a list of names and yours is in red underlined
I check it once then I check it twice ooh
Ooh look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me
Ooh look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me do
I don‘t trust nobody and nobody trusts me
I‘ll be the actress starring in your bad dreams
I don‘t trust nobody and nobody trusts me
I‘ll be the actress starring in your bad dreams
I don‘t trust nobody and nobody trusts me
I‘ll be the actress starring in your bad dreams
I don‘t trust nobody and nobody trusts me
I‘ll be the actress starring in your bad dreams
Look what you made me do
Look what you made me do
Look what you made me do
I‘m sorry the old Taylor can‘t come to the phone right now
Why
Oh ‘cause she‘s dead ohh
Ooh look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me
Ooh look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me do
Ooh look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me
Ooh look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me do‘‘‘
song=song.lower()
song=song.replace(‘\n‘,‘ ‘)
word=song.split(‘ ‘)
dic={}
keys=set(word)
for i in keys:
dic[i]=word.count(i)
print(dic)

技术分享

组合数据练习,英语词频统计实例上

标签:not   不可变   from   replace   使用   9.png   rust   img   play   

原文地址:http://www.cnblogs.com/coffee2/p/7577197.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!