返回顶部

收藏

从驼峰命名的串中提取单词子串形成数组

更多
#coding=utf8
result = []
def run2(name):
    for i in range(1,len(name)):
        if name[i].isupper():
            a = run2(name[i:])
            s = name[:i]
            a.append(s)
            return a
    return [name]

def run(name):
    s = len(result)
    for i in range(1,len(name)):
        if name[i].isupper():
            result.append(name[:i])
            run(name[i:])
            break

    if s == len(result): result.append(name)
    pass

def main():
    run('firstNameWomen')
    print result
    result2 = run2('firstNameWomen')
    print result2
    pass

if __name__ == '__main__':
    main()

标签:python

收藏

0人收藏

支持

0

反对

0

发表评论