字符串邻近去重
def special_func_order(seq
):
list_
= []
for i
in range(len(seq
) - 1):
if seq
[i
] != seq
[i
+ 1]:
list_
.append
(seq
[i
])
list_
.append
(seq
[-1])
if isinstance(seq
, list):
print(list_
)
if isinstance(seq
, tuple):
print(tuple(list_
))
else:
myseq
= ''.join
(list_
)
print(myseq
)
_list
= [1, 2, 3, 2, 3, 4, 5, 6, 6, 6, 8, 8]
_tuple
= (1, 2, 3, 2, 3, 4, 5, 6, 6, 6, 8, 8, 9)
_str
= 'AAABBBCDCCABBCcDD'
special_func_order
(_list
)
special_func_order
(_tuple
)
special_func_order
(_str
)
打印结果如下:
更多参考
https://blog.csdn.net/gymaisyl/article/details/85111561
转载请注明原文地址: https://lol.8miu.com/read-25598.html