我有一个标点符号列表,我希望循环从用户输入的句子中删除,它似乎连续忽略多个标点符号?
punctuation = ['(', ')', '?', ':', ';', ',', '.', '!', '/', '"', "'"]
usr_str=input('Type in a line of text: ')
#Convert to list
usr_list= list(usr_str)
#Checks if each item in list is punctuation, and removes ones that are
for char in usr_list:
if char in punctuation:
usr_list.remove(char)
#Prints resulting string
print(''.join(usr_list))
现在这适用于:
This is an example string, which works fine!
哪个打印:
This is an example string which works fine
但是,像这样:
Testing!!!!, )
给出:
Testing!!
在此先感谢您的帮助!