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

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

时间:2018-09-22 21:14:10      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:abc   div   for   http   数据   数据类型   对象   .com   can   

1.总结列表,元组,字典,集合的联系与区别:

列表:list [, ,]   list是一种有序的序列,可以随时添加和删除元素,元素类型可以不同。

元组: tuple[‘‘ ,‘‘ ]元组一旦创建,便不能修改,只能做读取操作。

字典:dict {key:value,}  dict的key 不能重复,必须是不可变对象。

集合:set {,,}  也是一组key的集合,key不能重复。

 

2.列表,元组,字典,集合的遍历。

列表:

li=list(abcde)
print(li)
for lis in li:
    print(lis)

运行结果:

技术分享图片

元组:

classmates=["Michale","Bob","Tracy","李三","Tracy",56]
print(classmates)
for tuple in classmates:
    print(tuple)

运行结果:技术分享图片

字典:

classmates={"Bob":75,"Michael":95,"Tracy":85}
print(classmates)
for dic in classmates:
    print(dic)

运行结果:

技术分享图片

集合:

s={1,2,3,4,4,6}
print(s)
for set in s:
    print(set)

运行结果:

技术分享图片

 

英文词频统计:

str=The steps that we left behind      Your lonely eyes stare back at mine      In pictures from that time     I hold my heart,closing my eyes     I see your smile,lies behind     In this place,you entered my life     How I wish,you were still mine     I know that if I see you again     Beside that cafe we met     I'd forget about the past     Lose track of time,with you     Talking about our lives     To show you a whole new side of me     And see the changes we've made,can we     Be more than we have been     Start our story again     All I can say,is tell you just one thing     好久不见     I hold my heart,closing my eyes     I see your smile,lies behind     In this place,you entered my life     How I wish,you were still mine     I know that if I see you again     Beside that cafe we met     I'd forget about the past     Lose track of time,with you     Talking about our lives     To show you a whole new side of me     And see the changes we've made,can we     Be more than we have been     Start our story again     All I can say,is tell you just one thing     好久不见
print(str.lower())
print(str.count("you"))

list=str.split()
print(list)
for song in list:
    print(song,list.count(song))

运行结果:

技术分享图片

 

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

标签:abc   div   for   http   数据   数据类型   对象   .com   can   

原文地址:https://www.cnblogs.com/cx1234/p/9691012.html

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