我有以下输入字符串:
text='''Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!'''
到目前为止,我已经将text
字符串拆分为list
,如下所示:
现在,我想使用strip
函数从上面的列表中删除不需要的字符,比如\n\n
和{
你能帮我一下吗??在
使用} 函数将允许您这样做。
我们需要用单个的
re
模块,^{\n
替换multilpe\n
出现,并删除字符串
然后分割你的文本。在
您可以使用列表理解来删除
这将使用空格或换行符拆分字符串
相关问题 更多 >
编程相关推荐