日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

组合数据类型练习,英文词频统计实例9-21

發(fā)布時間:2024/9/5 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 组合数据类型练习,英文词频统计实例9-21 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
  • 1、列表實例:由字符串創(chuàng)建一個作業(yè)評分列表,做增刪改查詢統(tǒng)計遍歷操作。例如,查詢第一個3分的下標,統(tǒng)計1分的同學有多少個,3分的同學有多少個等。 >>>score=list('21223113321') >>>print('作業(yè)評分列表:',score) >>>score.append('3') >>>print('增加:',score) >>>score.pop() >>>print('刪除:',score) >>>score.insert(2,'1') >>>print('插入:',score) >>>score[2]='2' >>>print('修改:',score) >>>print('第一個3分的下標:',score.index('3')) >>>print('1分的個數(shù):',score.count('1')) >>>print('3分的個數(shù):',score.count('3'))
  • 2、字典實例:建立學生學號成績字典,做增刪改查遍歷操作。 >>>d={'洪英杰':93,'郭子維':74,'王五':45,'徐均鈞':66} >>>print('學生成績字典:',d) >>>d['錢二']=92 >>>print('增加:',d) >>>d.pop('徐均鈞') >>>print('刪除:',d) >>>d['張三']=73 >>>print('修改:',d) >>>print('查詢李四成績:',d.get('李四',''))
  • 3、列表,元組,字典,集合的遍歷。 >>>ls=list("4613125646") >>>tu=tuple("4613125646") >>>s=set("4613125646") >>>d={'洪英杰':93,'郭子維':74,'王五':45,'徐均鈞':66} >>>print("列表:",ls) >>>for i in ls:print(i,end=' ') >>>print("\n") >>>print("元組:",tu) >>>for i in tu:print(i,end=' ') >>>print("\n") >>>print("集合:",s) >>>for i in s:print(i,end=' ') >>>print("\n") >>>print("字典:",d) >>>for i in d:print(i,end='\t') >>>print(d[i],end='\n')
  • 4、英文詞頻統(tǒng)計實例
  • 待分析字符串
  • 分解提取單詞
  • 大小寫 txt.lower()
  • 分隔符'.,:;?!-_’
  • 計數(shù)字典
  • 排序list.sort()
  • 輸出TOP(10)

      • faded = '''You were the shadow to my light Did you feel us? Another start You fade away Afraid our aim is out of sight Wanna see us Alive Where are you now? Where are you now? Where are you now? Was it all in my fantasy? Where are you now? Were you only imaginary? Where are you now? Atlantis Under the sea Under the sea Where are you now? Another dream The monster's running wild inside of me I'm faded I'm faded So lost, I'm faded I'm faded So lost, I'm faded These shallow waters never met what I needed I'm letting go a deeper dive Eternal silence of the sea. I'm breathing alive Where are you now? Where are you now? Under the bright but faded lights You've set my heart on fire Where are you now? Where are you now? Where are you now? Atlantis Under the sea Under the sea Where are you now? Another dream The monster's running wild inside of me I'm faded I'm faded So lost, I'm faded I'm faded So lost, I'm faded'''faded = faded.lower() for i in '?!,.\'\n':faded = faded.replace(i,' ') words = faded.split(' ')dic={} keys = set(words) for i in keys:dic[i]=words.count(i)c = list(dic.items()) c.sort(key=lambda x:x[1],reverse=True)for i in range(10):print(c[i])
      • 建立學生學號成績字典

        >>>score = {10:'41',20:'64',30:'71',40:'81',50:'91'} >>>print(score) >>>score[6] = '90' >>>print(score) >>>score.pop(6) >>>print(score)>>>for i in score:print("{:>2} : {:<2}".format(i,score.get(i)))

        列表,元組,字典,集合

        >>>ls=list("4613125646") >>>tu=tuple("4613125646") >>>se=set("4613125646") >>>d={'阿一':93,'阿二':74,'阿三':45,'阿四':66} >>>print("列表:",ls) >>>for i in ls:print(i,end=' ') >>>print("\n") >>>print("元組:",tu) >>>for i in tu:print(i,end=' ') >>>print("\n") >>>print("集合:",se) >>>for i in se:print(i,end=' ') >>>print("\n") >>>print("字典:",d) >>>for i in d:print(i,end='\t')print(d[i],end='\n')

        歌詞統(tǒng)計

        >>>song = '''Vincent,Don McLean. Starry starry nightpaint your palette blue and greylook out on a summer\'s daywith eyes that know the darkness in my soul.Shadows on the hillssketch the trees and the daffodilscatch the breeze and the winter chillsin colors on the snowy linen land.And now I understandwhat you tried to say to meand how you suffered for your sanityand how you tried to set them free.They would not listen they did not know howperhaps they\'ll listen now.Starry starry nightflaming flowers that brightly blazeswirling clouds in violet hazereflect in Vincent\'s eyes of China blue.Colors changing huemorning fields of amber grainweathered faces lined in painare smoothed beneath the artist\'s loving hand.And now I understandwhat you tried to say to meand how you suffered for your sanityand how you tried to set them free.They would not listen they did not know howperhaps they\'ll listen now.For they could not love youbut still your love was trueand when no hope was left in sight on thatstarry starry night.You took your life as lovers often do,But I could have told you Vincentthis world was never meant for one as beautiful as you.Starry starry nightportraits hung in empty hallsframeless heads on nameless wallswith eyes that watch the world and can\'t forget.Like the stranger that you\'ve metthe ragged men in ragged clothesthe silver thorn of bloddy roselie crushed and broken on the virgin snow.And now I think I knowwhat you tried to say to meand how you suffered for your sanityand how you tried to set them free.They would not listen they\'re not listening stillperhaps they never will.'''>>>song = song.lower() >>>for i in '?!,.\'\n': >>> song = song.replace(i,' ') >>>words = song.split(' ')>>>dic={} >>>keys = set(words) >>>for i in keys: >>>dic[i]=words.count(i)>>>c = list(dic.items()) >>>c.sort(key=lambda x:x[1],reverse=True)>>>for i in range(10):>>>print(c[i])

        ?

轉(zhuǎn)載于:https://www.cnblogs.com/yingja-hong/p/7567595.html

總結(jié)

以上是生活随笔為你收集整理的组合数据类型练习,英文词频统计实例9-21的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。