2020年3月31日

Python dictdiffer模块

摘要: Let’s start with an example on how to find the diff between two dictionaries using diff() method: from dictdiffer import diff, patch, swap, revert fir 阅读全文

posted @ 2020-03-31 19:24 不要挡着我晒太阳 阅读(1263) 评论(0) 推荐(0) 编辑

python文件操作练习

摘要: 1.获取后缀名 import os file_ext = os.path.splittext('./data/py/test.py') front,ext = file_ext print(front,ext) #'./data/py/test' #'.py' 2.创建文件夹 def mkdir(p 阅读全文

posted @ 2020-03-31 19:17 不要挡着我晒太阳 阅读(389) 评论(0) 推荐(0) 编辑

判断str1是否由str2旋转而来

摘要: stringbook旋转后得到bookstring,写一段代码验证str1是否为str2旋转得到。 思路 转化为判断:str1是否为str2+str2的子串(因为该思路比较巧妙,故记录下来) def is_rotation(s1: str, s2: str) -> bool: if s1 is No 阅读全文

posted @ 2020-03-31 16:40 不要挡着我晒太阳 阅读(186) 评论(0) 推荐(0) 编辑

数据库字段名批量转化为驼峰格式

摘要: import re def camel(s): s = re.sub(r"(\s|_|-)+", " ", s).title().replace(" ", "") return s[0].lower() + s[1:] # 批量转化 def batch_camel(slist): return [c 阅读全文

posted @ 2020-03-31 15:38 不要挡着我晒太阳 阅读(1074) 评论(0) 推荐(0) 编辑

字符串切片操作——查找替换3或5的倍数

摘要: [str("java"[i%3*4:]+"python"[i%5*6:] or i) for i in range(1,15)] 阅读全文

posted @ 2020-03-31 14:06 不要挡着我晒太阳 阅读(248) 评论(0) 推荐(0) 编辑

待填坑

摘要: 今天看见一个烧脑的代码,一时没看懂结果,刨个坑,看懂填 def product(*args, repeat=1): pools = [tuple(pool) for pool in args] * repeat result = [[]] for pool in pools: result = [x 阅读全文

posted @ 2020-03-31 13:28 不要挡着我晒太阳 阅读(122) 评论(0) 推荐(0) 编辑

导航