1. 程式人生 > >組合數據練習,英語詞頻統計實例上

組合數據練習,英語詞頻統計實例上

games 1-1 合數 ice 語句 rime ict 項目 tuple

1

>>> d={‘01‘:95,‘02‘:92,‘03‘:86,‘04‘:70}
>>> print(d)
{‘01‘: 95, ‘02‘: 92, ‘03‘: 86, ‘04‘: 70}
>>> d[‘05‘]=80
>>> print(d)
{‘01‘: 95, ‘02‘: 92, ‘03‘: 86, ‘04‘: 70, ‘05‘: 80}
>>> d.pop(‘02‘)
92
>>> print(d)
{‘01‘: 95, ‘03‘: 86, ‘04‘: 70, ‘05‘: 80}
>>> d[‘03‘]=88
>>> print(d)
{‘01‘: 95, ‘03‘: 88, ‘04‘: 70, ‘05‘: 80}
>>> d[‘05‘]
80

2

ls=list(‘2345679900‘)
tu=tuple(‘2354687879‘)
print(ls)
print(tu)
dc=dict(zip(ls,tu))
print(dc)
print(‘ls遍歷\n‘)
for i in ls:
print(i)
print(‘tu遍歷\n‘)
for i in tu:
print(i)

print(‘dict遍歷\n‘)
for i in dc:
print(i,dc[i])

技術分享

3

列表和元組是有序的,字典和集合是無序的,列表是可變的數據類型,即這種類型是可以被改變的,並且列表是可以嵌套的,列表通過中括號中用逗號分隔的項目定義。元組是不可變的。即你不能修改元組。元組通過圓括號中用逗號分隔的項目定義。元組通常用在使語句或用戶定義的函數能夠安全的采用一組值的時候,即被使用的元組的值不會改變。元組可以嵌套。字典通過大括號中用鍵值對和逗號分隔的項目定義,用空間換取時間。集合只有鍵沒有值,可以把元組或序列中不重復的找出來,並可以做交集並集等操作

4

song=‘‘‘I don‘t like your little games
Don‘t like your tilted stage
The role you made me play of the fool
No I don‘t like you
I don‘t like your perfect crime
How you laugh when you lie
You said the gun was mine
Isn‘t cool
No I don‘t like you ooh
But I got smarter I got harder in the nick of time
Honey I rose up from the dead I do it all the time
I got a list of names and yours is in red underlined
I check it once then I check it twice ooh
Ooh look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me
Ooh look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me do
I don‘t like your kingdom keys
They once belonged to me
You asked me for a place to sleep
Locked me out and threw a feast what
The world moves on another day another drama drama
But not for me not for me all I think about is karma
And then the world moves on but one thing‘s for sure
Maybe I got mine but you‘ll all get yours
But I got smarter I got harder in the nick of time
Honey I rose up from the dead I do it all the time
I‘ve got a list of names and yours is in red underlined
I check it once then I check it twice ooh
Ooh look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me
Ooh look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me do
I don‘t trust nobody and nobody trusts me
I‘ll be the actress starring in your bad dreams
I don‘t trust nobody and nobody trusts me
I‘ll be the actress starring in your bad dreams
I don‘t trust nobody and nobody trusts me
I‘ll be the actress starring in your bad dreams
I don‘t trust nobody and nobody trusts me
I‘ll be the actress starring in your bad dreams
Look what you made me do
Look what you made me do
Look what you made me do
I‘m sorry the old Taylor can‘t come to the phone right now
Why
Oh ‘cause she‘s dead ohh
Ooh look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me
Ooh look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me do
Ooh look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me
Ooh look what you made me do
Look what you made me do
Look what you just made me do
Look what you just made me do‘‘‘
song=song.lower()
song=song.replace(‘\n‘,‘ ‘)
word=song.split(‘ ‘)
dic={}
keys=set(word)
for i in keys:
dic[i]=word.count(i)
print(dic)

技術分享

組合數據練習,英語詞頻統計實例上