首页 > 其他 > 详细

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

时间:2018-09-22 20:58:18      阅读:34      评论:0      收藏:0      [点我收藏+]

标签:合数   hat   运行   tell   ole   rac   pla   lose   see   

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))

运行结果:

技术分享图片

 

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

标签:合数   hat   运行   tell   ole   rac   pla   lose   see   

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

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号