首页 > 其他 > 详细

驼峰式命名改下划线命名

时间:2018-12-20 22:00:26      阅读:170      评论:0      收藏:0      [点我收藏+]
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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!