码迷,mamicode.com
首页 > 其他好文 > 详细

Intelligent Poetry

时间:2019-01-18 17:21:00      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:rom   nbsp   replace   read   rand   microsoft   lin   dig   poetry   

Readme:

  Creat poems.

技术分享图片
 1 import re
 2 import random
 3 from collections import Counter
 4 
 5 def Creat_Poem(number):
 6     w=random.sample(poem,number)
 7     for i in range(number//4):
 8         print(w[i],end=‘‘)
 9     print(,end=‘‘)
10     for i in range(number//4,number//2):
11         print(w[i],end=‘‘)
12     print()
13     for i in range(number//2,number//4*3):
14         print(w[i],end=‘‘)
15     print(,end=‘‘)
16     for i in range(number//4*3,number):
17         print(w[i],end=‘‘)
18     print()
19     return
20 
21 dic=[]
22 data=open(tangshi.txt,r)
23 for i in data.readlines():
24     dic.append(i.strip().replace(,‘‘).replace(,‘‘).replace(,‘‘).replace(,‘‘).replace(,‘‘).replace(,‘‘).replace(,‘‘))
25 word=‘‘.join(dic)
26 word_str=re.sub(r"(?<=\w)","",word)
27 word_list= list(word_str)
28 a= [i for i in word_list if not str(i).isdigit()]
29 s =Counter(a).most_common(300)
30 poem=[]
31 for i in s:
32     poem.append(i[0])
33 number=int(input(Merciful Sir,\n\tPlease input the Number of Words:\n\t))
34 print()
35 Creat_Poem(number)
Intelligent Poetry

 

Intelligent Poetry

标签:rom   nbsp   replace   read   rand   microsoft   lin   dig   poetry   

原文地址:https://www.cnblogs.com/bingoyes/p/10288413.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!