【发布时间】:2021-06-19 13:33:38
【问题描述】:
给定输入:
Democr _acy , is overrat _ed .
期望的输出:
Democracy, is overrated.
这是我的代码:
sentence=input()
punctuation = "!\"#$%&'()*+,-./:;<=>?@[\]^`{|}~"
suffixes = ["acy", "ance", "ence", "dom", "er", "or", "ism", "ist",
"ty", "ment", "ness", "ship", "sion", "tion", "ate",
"en", "fy", "ize", "able", "ible", "al",
"esque", "ful", "ic", "ous", "ish", "ive",
"less", "ed", "ing", "ly", "ward", "wise"]
sentence_list = sentence.split('_')
c=""
if c not in punctuation:
print("".join(sentence_list))
elif c in punctuation:
for c in sentence:
print("".join(sentence_list).split(c))
如您所见,我的输出有 29 个不同的列表,但我只想要其中一个。 我想从单词中删除 '' 并加入我从中删除 '' 的标点符号和单词。 当我写这样的代码时:
sentence_list = sentence.split('_')
print("".join(sentence_list))
'_'和标点符号消失。我在哪里做错了?
【问题讨论】:
标签: python-3.x join split punctuation