If order does not matter, you can use foo = "mppmt" "".join(set(foo)) set() will create a set of unique letters in the string, and "".join() will join the letters back to a string in arbitrary order. If order does matter,…
需求:在一个字符串中, 如果遇到连续重复的字符只出现一个,(不是去重) 例:str1 = 'aabbccddaabbccdd' 输出结果为:‘abcdabcd’ 具体实现代码如下: def func(_str): _list = list(_str) n = len(_list) if n <= 1: print(_str) return list1 = [] for i in range(n-1): if _list[i] != _list[i+1]: list1.append(_list[i…