如何刪除字符串中的重複字母?在Python中刪除重複的字母
試過這種沒有成功..
def shorten_string(char_str):
new=''
for i in range(0,len(char_str)-1):
if char_str[i-1] != char_str[i]:
new += char_str[i]
return new
編輯:誤區一:我不想刪除所有重複characthers。只要它們按順序重複。
input: lloolleellaa
outpu: lolela
可以添加樣本輸出和輸入。 – harshil9968
@ harshil9968檢查帖子的第一行。 –
請參閱http://stackoverflow.com/a/9841401/3832970 –