移除连续重复的字符串元素

来源:互联网 发布:人脸识别原理及算法 编辑:程序博客网 时间:2024/04/28 00:58

dive into python P350

移除连续重复的字符串元素


b='abccdefekjllj'

def remove():

    a2=b[0]
    for i in b[1:]:
        if a2[-1]!=i:
            a2+=i
    print a2   #abcdefekjlj
0 0
原创粉丝点击