组合数据类型练习,英文词频统计实例上(2017.9.22)
生活随笔
收集整理的這篇文章主要介紹了
组合数据类型练习,英文词频统计实例上(2017.9.22)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
字典實例:建立學生學號成績字典,做增刪改查遍歷操作。
?
sno=['33號','34號','35號','36號'] grade=[100,90,80,120] d={'33號':100,'34號':90,'35號':80,'36號':120} print(d) print('每個學號對應分數:',d.items()) print('彈出35號的分數:',d.pop('35號')) print('獲取學號:',d.keys()) print('獲取分數:',d.values()) print(d.get('38號','38號已經轉系'))
?
二、列表,元組,字典,集合的遍歷。
總結列表,元組,字典,集合的聯系與區別。
代碼:
list=['1','3','1','4','9','9'] for i in list:print(i) tu=tuple('i love you') for i in tu:print(i) d={'呆梨':'I','大太陽':'love','小呆子':'you'} for i in d:print(i,d[i]) set=set(list) for i in set:print(i,tu)三、英文詞頻統計實例
待分析字符串
分解提取單詞
單詞計數字典
?代碼:
girl='''Remembering me, Discover and see All over the world, She's known as a girl To those who a free, The mind shall be key Forgotten as the past 'Cause history will lastGod is a girl, Wherever you are, Do you believe it, can you recieve it? God is a girl, Whatever you say, Do you believe it, can you recieve it? God is a girl.''' girl=girl.lower() for i in ',?': girl=girl.replace(i,' ')words=girl.split(' ')print(words) dict={} for i in words:dict[i]=words.count(i) print(dict)結果:
?
?
?
?
轉載于:https://www.cnblogs.com/laidaili/p/7573304.html
總結
以上是生活随笔為你收集整理的组合数据类型练习,英文词频统计实例上(2017.9.22)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 浅析C语言中assert的用法(转)
- 下一篇: C语言程序设计预报作业