python字符串添加字符_在python中向字符串追加字符

我试图解决以下问题:

字符串“PAYPALISHIRING”在给定的行数上以锯齿形模式写入,如下所示:(您可能希望以固定字体显示此模式,以提高可读性)P A H N

A P L S I I G

Y I R

然后一行一行地读:“pahnaplshigyir”

编写将接受字符串的代码,并在给定行数的情况下进行此转换:

字符串转换(字符串s,int numRows)

我已经写了下面的代码,但是粗体部分有错误

“TypeError:不支持+:'NoneType'和'unicode'的操作数类型”class Solution(object):

def convert(self, s, numRows):

"""

:type s: str

:type numRows: int

:rtype: str

"""

if numRows==1:

return s

templist=[None]*numRows

ret=" "

curRow=0

goingDown=0

for each_char in s:

if templist[curRow]:

templist[curRow]=each_char

else:

**templist[curRow]=templist[curRow] + each_char**

if (curRow==numRow-1 or curRow == 0):

goingDown = not goingDown

if goingDown:

curRow=curRow+1

else:

curRow=curRow-1

for each_str in templist:

ret=ret+each_str

print ret

我在这方面做错了什么吗。如果有人能在这里指出问题,那就太好了。

提前谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值