在 Python 中,我想从字符串中删除重复的字母,而不是数字或空格。我想出了:
result = []
seen = set()
for char in string:
if char not in seen:
seen.add(char)
result.append(char)
return "".join(result)
但这使得:
>>> delete_duplicate_letters("13 men were wounded in an explosion yesterday around 3:00pm.")
13 menwroudiaxplsyt:0.
当我想要:
>>> delete_duplicate_letters("13 men were wounded in an explosion yesterday around 3:00pm.")
13 men wr oud i a xpls yt 3:00.
我尝试使用letter
而不是函数和语句等char
,但我无法得到任何工作。isalpha()
if int