驼峰式命名改下划线命名

import sys
import re
if __name__ == "__main__":
    # 读取第一行的n
    n = int(sys.stdin.readline().strip())
    str = []
    for i in range(n):
        # 读取每一行
        line = sys.stdin.readline().strip()
        # 匹配正则,匹配小写字母和大写字母的分界位置
        p = re.compile(r'([A-Z][a-z]*)')
        # 这里第二个参数使用了正则分组的后向引用
        sub = re.findall(p, line)
        print(sub)
        ret = []
        temp = ''
        for index, item in enumerate(sub):
            if len(item) > 1:
                if len(temp) > 1:
                    ret.append(temp)
                    temp = ''
                ret.append(item)
            else:
                temp += item
                if index == len(sub)-1:
                    ret.append(temp)
        ret = [i.lower() for i in ret]
        str.append(ret)
    for i in str:
        print(str)
原文地址:https://www.cnblogs.com/l-jie-n/p/10152665.html