清除句子中的某些字符

时间:2018-10-16 16:23:39

标签: python python-3.x

我无法理解为什么 c 仍在列表中?

phrase = "Don't panic!" 
plist = list(phrase)

# Remove the characters we're not interested in
for i in plist:
    if i not in 'on tap':
        plist.remove(i)

print(plist)
print(''.join(plist))

当我运行脚本(Python 3.7)时,输出为:

['o', 'n', 't', ' ', 'p', 'a', 'n', 'c']
ont panc

0 个答案:

没有答案