python:MySplit():以任意单字符为标志分隔字符串(除了反斜杠\)

MySplit():以任意单字符为标志分隔字符串(除了反斜杠\)(转义符问题)

# split a string by q no matter how many q separated them
def mysplit(str, q)   :
    b = str.split(q)
    ans = list()
    for i in range(len(b)):
        if b[i] != '':
            ans.append(b[i])
    return ans
    
######################
# 例子
a = mysplit('qqwweeqqwweecamsceesac', 'ee')
print(a)
# ['qqww', 'qqww', 'camsc', 'sac']
posted on 2021-01-19 21:27  摸鱼time  阅读(300)  评论(0编辑  收藏  举报