这是一位多才多艺的python古风作词家,她会每秒钟生成一句歌词哟。
这是源码:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21# coding=gbk
import random
import time
two_words=[u"朱砂",u"天下",u"杀伐",u"人家",u"韶华",u"风华",u"繁华",u"血染",u"墨染",u"白衣",u"素衣",u"嫁衣",u"倾城",u"孤城",u"空城",u"旧城",u"旧人",u"伊人",u"心疼",u"春风",u"古琴",u"无情",u"迷离",u"奈何",u"断弦",u"焚尽",u"散乱",u"陌路",u"乱世",u"笑靥",u"浅笑",u"明眸",u"轻叹",u"烟火",u"一生",u"三生",u"浮生",u"桃花",u"梨花",u"落花",u"烟花",u"离殇",u"情殇",u"爱殇",u"剑殇",u"灼伤",u"仓皇",u"匆忙",u"陌上",u"清商",u"焚香",u"墨香",u"微凉",u"断肠",u"痴狂",u"凄凉",u"黄梁",u"未央",u"成双",u"无恙",u"虚妄",u"凝霜",u"洛阳",u"长安",u"江南",u"忘川",u"千年",u"纸伞",u"烟雨",u"回眸",u"公子",u"红尘",u"红颜",u"红衣",u"红豆",u"红线",u"青丝",u"青史",u"青冢",u"白发",u"白首",u"白骨",u"黄土",u"黄泉",u"碧落",u"紫陌"]
four_words=[u"情深缘浅",u"情深不寿",u"莫失莫忘",u"阴阳相隔",u"如花美眷",u"似水流年",u"眉目如画",u"曲终人散",u"繁华落尽",u"不诉离殇",u"一世长安"]
sentence_model=[u"xx,xx,xx了xx。",u"xxxx,xxxx,不过是一场xxxx。",u"你说xxxx,我说xxxx,最后不过xxxx。",u"xx,xx,许我一场xxxx。",u"一x一x一xx,半x半x半xx。",u"你说xxxxxxxx,后来xxxxxxxx。",u"xxxx,xxxx,终不敌xxxx。"]
def get_sentence():
model=sentence_model[random.randint(0, len(sentence_model)-1)]
while "xxxx" in model:
model=model.replace("xxxx",four_words[random.randint(0, len(four_words)-1)],1)
while "xx" in model:
model=model.replace("xx",two_words[random.randint(0, len(two_words)-1)],1)
while "x" in model:
model=model.replace("x",two_words[random.randint(0, len(four_words)-1)][random.randint(0, 1)],1)
print model
i=0
while(1):
print i
get_sentence()
i=i+1
time.sleep(1)
下面是部分歌词赏析: