组合数据类型,英文词频统计
Posted spaldingwen
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了组合数据类型,英文词频统计相关的知识,希望对你有一定的参考价值。
列表:用list()函数或者[]创建,是可变序列。
元组:用()或者tuple()函数来实现;是不可变序列。
字典:用dict()函数或者{}创建,使用键-值(key-value)存储,键是不可变的对象。
集合:用set()函数或者{}创建,是一个无序不重复元素集。
#列表 list=[‘Tt‘,‘Aa‘,‘Bb‘,10] print(list) for A1 in list: print(A1) #元组 Tuple1=(‘abcdefg‘) print(Tuple1) for B1 in Tuple1: print(B1) #集合 Set1={2,4,6,8} print(Set1) for c in Set1: print(c) #字典 dict1 = {‘a‘:55,‘b‘:66,‘c‘:77} print(dict1) for d in dict1: print(d,dict1[d])
hh=‘‘‘You‘re on the phone with your girlfriend She‘s upset She‘s going off about something that you said ‘Cause she doesn‘t get your humor like I do I‘m in my room It‘s a typical Tuesday night I‘m listening to the kind of music she doesn‘t like And she‘ll never know your story like I do But she wears short skirts I wear T-shirts She‘s cheer captain And I‘m on the bleachers Dreaming about the day when you wake up And find that what you‘re looking for has been here the whole time If you can see I‘m the one who understands you Been here all along so why can‘t you see You belong with me You belong with me Walkin‘ the streets with you and your worn-out jeans I can‘t help thinking this is how it ought to be Laughing on a park bench thinking to myself Hey isn‘t this easy And you‘ve got a smile that could light up this whole town I haven‘t seen it in a while since she brought you down You say you‘re fine I know you better then that Hey what you doing with a girl like that She wears high heels I wear sneakers She‘s cheer captain and I‘m on the bleachers Dreaming about the day when you wake up And find that what what you‘re looking for has been here the whole time If you can see that I‘m the one who understands you Been here all along so why can‘t you see You belong with me Standing by and waiting at your back door All this time how could you not know Baby you belong with me You belong with me Oh I remember you drivin‘ to my house in the middle of the night I‘m the one who makes you laugh When you know you‘re about to cry And I know your favorite songs And you tell me about your dreams I think I know where you belong I think I know it‘s with me Can‘t you see that I‘m the one who understands you Been here all along so why can‘t you see You belong with me Standing by and waiting at your back door All this time How could you not know Baby you belong with me You belong with me You belong with me Have you ever thought just maybe You belong with me You belong with me‘‘‘.lower() aa = ‘‘‘,."?!‘‘‘ for word in aa: str2 =hh.replace(‘word‘,‘ ‘) hh =hh.replace(‘ ‘,‘‘) hh = hh.strip() hh = hh.split(‘ ‘) print(hh) strSet=set(hh) for word in strSet: print(word,hh.count(word))
dict={} #单词计数字典
for word in hh:
dict[word] = hh.count(word)
print(len(dict),dict)