【发布时间】:2013-09-18 21:24:51
【问题描述】:
如何使用 Python 从字符串中删除重复字符?例如,假设我有一个字符串:
foo = "SSYYNNOOPPSSIISS"
如何制作字符串:
foo = SYNOPSIS
我是 python 的新手,我已经厌倦了,它正在工作。我知道有一种聪明和最好的方法来做到这一点..只有经验才能证明这一点..
def RemoveDupliChar(Word):
NewWord = " "
index = 0
for char in Word:
if char != NewWord[index]:
NewWord += char
index += 1
print(NewWord.strip())
注意:顺序很重要,此问题与this one 不同。
【问题讨论】:
标签: python string text-processing