热线电话:13121318867

登录
2019-01-22 阅读量: 1908
将python字符串拆分为分隔符但是特定的分隔符

有没有办法分割python字符串而不使用for循环,基本上将中间的字符串拆分为最接近的分隔符。

比如:

The cat jumped over the moon very quickly.

分隔符将是空格,结果字符串将是:

The cat jumped over

the moon very quickly.

0.0000
3
关注作者
收藏
评论(1)

发表评论
啊啊啊啊啊吖
2019-01-22
目前想到的办法参考:s = "The cat jumped over the moon very quickly" l = s.split() s1 = ' '.join(l[:len(l)//2]) s2 = ' '.join(l[len(l)//2 :]) print(s1) print(s2)
0.0000 0 0 回复