【发布时间】:2018-08-19 08:03:05
【问题描述】:
我有以下输入字符串:
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,如下所示:
list=['Although', 'never', 'is', 'often', 'better', 'than', '*right*', 'now.\n\nIf', 'the', 'implementation', 'is', 'hard', 'to', 'explain,', "it's", 'a', 'bad', 'idea.\n\nIf', 'the', 'implementation', 'is', 'easy', 'to', 'explain,', 'it', 'may', 'be', 'a', 'good', 'idea.\n\nNamespaces', 'are', 'one', 'honking', 'great','idea', '--', "let's", 'do', 'more', 'of', 'those!']
现在,我想使用strip 函数从上面的列表中删除不需要的字符,例如\n\n 和--。
你能帮我解决这个问题吗?
【问题讨论】:
-
stripped = list(map(str.strip,old_list)) -
请提供您尝试过的代码。
-
到目前为止你的想法是什么?
标签: python string python-3.x