【发布时间】:2017-12-21 18:22:53
【问题描述】:
我有一个令牌列表。有些以@ 符号开头。我想将所有这些字符串更改为通用的@user。我试过这个:
>>> words = ['@john', 'nina', 'michael', '@bebeto']
>>> words = [w.replace(w, '@user') for w in words if w.startswith('@')]
>>> words
['@user', '@user']
>>>
我在这里做错了什么?
【问题讨论】:
-
你想要的输出是什么?
-
@Ajax1234 我想
['@user', 'nina', 'michael', '@user']
标签: python string python-3.x replace