私が書いたコードで何が起こっているのかを実際に評価するのに役立つ必要があります。Python 3.xx - 文字列から連続した数字/文字を削除する
このように機能するためのものです:
input: remove_duple('WubbaLubbaDubDub')
output: 'WubaLubaDubDub'
別の例:
input: remove_duple('aabbccdd')
output: 'abcd'
私はまだ初心者です、私が知りたいのですが私のコードで容易と間違っているものを両方それを行う方法。
def remove_duple(string):
to_test = list(string)
print (to_test)
icount = 0
dcount = icount + 1
for char in to_test:
if to_test[icount] == to_test[dcount]:
del to_test[dcount]
print ('duplicate deleted')
print (to_test)
icount += 1
elif to_test[icount] != to_test[dcount]:
print ('no duplicated deleted')
print (to_test)
icount += 1
print ("".join(to_test))
[正規表現](https://ideone.com/BpT3NE)でどのようにシンプルに見えるかを見てみましょう。 –