Skip to content

Instantly share code, notes, and snippets.

@p3nj
Created August 6, 2018 16:20
Show Gist options
  • Save p3nj/0d6ba63bbd6dfb378288fac6cb86c4d4 to your computer and use it in GitHub Desktop.
Save p3nj/0d6ba63bbd6dfb378288fac6cb86c4d4 to your computer and use it in GitHub Desktop.
歌詞歌詞詞頻統計
lyrics = []
while True:
i = input()
if i == '===':
break
i = i.split()
for j in i:
j = j.lower()
if j == "we're":
lyrics.append('we')
lyrics.append('are')
continue
if j == "i'd":
lyrics.append('i')
lyrics.append('would')
continue
j = j.replace('.', '').replace(':', '').replace('?', '').replace(',', '').replace('\n', '')
lyrics.append(j)
d = {}
for i in sorted(lyrics):
if i in d:
d[i] += 1
continue
d[i] = 1
for key, value in d.items():
print('{}:{}'.format(key,value))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment