组合数据类型,英文词频统计
Posted cx1234
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了组合数据类型,英文词频统计相关的知识,希望对你有一定的参考价值。
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))
运行结果:
以上是关于组合数据类型,英文词频统计的主要内容,如果未能解决你的问题,请参考以下文章