深度学习|用Python给自己写一个藏头诗吧

读入数据

# 使用pandas读入数据
import pandas as pd
poems_text = pd.read_table('./poems_clean.txt', header=None)
poems_text.columns = ["text"]       #加上text
# 查看文本
poems_text.head()       #诗名:内容

结果如下图:
在这里插入图片描述

import string       #处理字符串
import numpy as np

poems_new = []
for line in poems_text['text']:  # poems_text[0]的第0列,指
    title, poem = line.split(':')       #按:切割
    poem = poem.replace(' ', '') #将空格去掉
    poem = 'bbb' + poem
    poems_new.append(list(poem))

数据整理

XY  =[]
for poem in poems_new:
    for i in range(len(poem) - 3):       #前三个字是bbb
        x1 = poem[i]
        x2 = poem[i+1]
        x3 = poem[i+2]
        
        y = poem[i+3]                    #要猜的字
        XY.append([x1,</
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值