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

去除列表中字符串中的空格换行等

时间:2017-07-09 18:22:45      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:top   cal   art   空格   pre   rip   topic   height   bsp   

 

for x in topic_replay:
# 去掉在x左右的空白,\t,\n和\r字符.
x1 = x.strip(‘ \t\n\r‘)
if x1 !=‘‘:
topic_replay_end.append(x1)

 

技术分享

技术分享

 

 

 

# 先将文章中的\r 都去掉,有些单独的‘\r‘ 就变成了空的列表元素:‘‘,再用if 来判断下就好了
artical_end = []
for x in article:
x1 = x.replace(‘\r‘,‘‘)
if x1 != ‘‘:
artical_end.append(x1)

 

去除列表中字符串中的空格换行等

标签:top   cal   art   空格   pre   rip   topic   height   bsp   

原文地址:http://www.cnblogs.com/vivivi/p/7142069.html

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