列表中的数据如下所示:
data = [u'Gluten free menu includes gluten free rolls for sandwiches and gluten free brownies! There are also many dishes that can be adjusted to be gluten free.',
u"They use the same slicing machine for diary and meats. Manager was knowledgable about food prep, servers were not.\r\r\r\n\r\r\r\nWe've been very select about which foods to order, but haven't had any issues.",
u'The restaurant has a whole gluten free section of the menu and says that they will accommodate any allergies. I myself do not have allergies but grandchildren have dairy, egg nut and niece has gluten.',
u'Got sick from crosscontam Bfast. I suggest ordering the Mexican dishes if cross contam is an issue. My fav place in Sedona tho food is great!']
我想要的结果是:
Gluten free menu includes gluten free rolls for sandwiches and gluten free brownies! There are also many dishes that can be adjusted to be gluten free.
They use the same slicing machine for diary and meats. Manager was knowledgable about food prep, servers were not. We've been very select about which foods to order, but haven't had any issues.
The restaurant has a whole gluten free section of the menu and says that they will accommodate any allergies. I myself do not have allergies but grandchildren have dairy, egg nut and niece has gluten.
Got sick from crosscontam Bfast. I suggest ordering the Mexican dishes if cross contam is an issue. My fav place in Sedona tho food is great!
我尝试了不同的代码,包括以下示例:
for sentence in data:
print sentence.strip()
似乎什么都没用。有什么建议吗?提前谢谢
假设多行字符串是使用三个引号正确创建的
str.strip()
只去除尾随和前导空格,而不是中间的空格最简单的方法是首先
split()
任何空格上的完整字符串,然后str.join()
使用一个空格返回示例-
用编辑过的真实数据演示-
给出(你的例子):
你可以做:
印刷品:
相关问题 更多 >
编程相关推荐