且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从python中的字符串中删除连续的重复字符

更新时间:2023-01-12 21:41:44

您的行remove_dups(s,ind)是问题.它不对返回的值做任何事情.如果您仔细阅读了代码,则在顶层函数调用中,将在顶部分配s=text,然后在底部返回s,而无需修改s的值.提示是,在打印正确答案后,您将最后打印原始文本.
尝试s = remove_dups(s, ind)

Your line remove_dups(s,ind) is the problem. It's not doing anything with the returned value. If you read through your code, in the top level function call you're assigning s=text at the top, then returning s at the bottom, without ever modifying the value of s. The clue is that you're printing the original text last, after you've printed the correct answer.
Try s = remove_dups(s, ind)