我无法理解为什么 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