综合练习

song = '''
   An empty street
An empty house
A hole inside my heart
I'm all alone
The rooms are getting smaller
I wonder how
I wonder why
I wonder where they are
The days we had
The songs we sang together
Oh yeah
And oh my love
I'm holding on forever
Reaching for a love that seems so far
So i say a little prayer
And hope my dreams will take me there
Where the skies are blue to see you once again, my love
Over seas and coast to coast
To find a place i love the most
Where the fields are green to see you once again, my love
I try to read
I go to work
I'm laughing with my friends
But i can't stop to keep myself from thinking
Oh no I wonder how
I wonder why
I wonder where they are
The days we had
The songs we sang together
Oh yeah And oh my love
I'm holding on forever
Reaching for a love that seems so far Mark:
To hold you in my arms
To promise you my love
To tell you from the heart
You're all i'm thinking of
I'm reaching for a love that seems so far 
So i say a little prayer
And hope my dreams will take me there
Where the skies are blue to see you once again, my love
Over seas and coast to coast
To find a place i love the most
Where the fields are green to see you once again,my love
say a little prayer
dreams will take me there
Where the skies are blue to see you once again
 '''
sep=''',.?!:'-'''
for c in sep:
    song = song.replace(c,'')
wordList = song.lower().split()

wordDict={}
'''wordSet=set(wordList)
for w in wordSet:
    wordDict[w]=wordList.count(w)
'''
for w in wordList:
    wordDict[w]=wordDict.get(w,0)+1
    dictList = list(wordDict.items())
    dictList.sort(key=lambda x:x[1],reverse=True)

    for w in dictList:
        print(w)

posted @ 2018-03-26 11:15  116王梓斌  阅读(146)  评论(0编辑  收藏  举报