上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 21 下一页

2020年3月31日

判断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 不要挡着我晒太阳 阅读(1079) 评论(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) 编辑

2020年3月30日

python chain模块

摘要: chain函数串联a和b,兼顾内存效率同时写法更加优雅。 from itertools import chain a = [1,3,5,0] b = {'a':1,'b':2} for i in chain(a,b): print(i) #result:1,3,5,0,a,b for i in ch 阅读全文

posted @ 2020-03-30 20:01 不要挡着我晒太阳 阅读(2640) 评论(0) 推荐(0) 编辑

Python标准库模块之heapq

摘要: 该模块提供了堆排序算法的实现。堆是二叉树,最大堆中父节点大于或等于两个子节点,最小堆父节点小于或等于两个子节点。 创建堆 heapq有两种方式创建堆, 一种是使用一个空列表,然后使用heapq.heappush()函数把值加入堆中,另外一种就是使用heap.heapify(list)转换列表成为堆结 阅读全文

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

Python中的metaclass

摘要: Class也是Object 在理解metaclass之前,我们需要先理解Python中的class。从某种程度上来说,Python中的class的定位比较特殊。 对于大部分面向对象语言来说,class是一段定义了如何产生object的代码块。在Python中这一定义也成立: >>> class ex 阅读全文

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

python eval和exec的区别

摘要: eval:可以把字符串里的字符转换为可执行代码,但只支持一行字符。可以返回执行后得到的值。如下: f = "3+6+9+8" s = eval(f) print(s) 输出: "C:\Program Files\python3\python3.exe" D:/codes_py3/luhy_tool/ 阅读全文

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

2020年3月27日

flask源码分析

摘要: 通过查看源码,我们知道app.run() 方法其实是执行了run_simple() 方法,源码如下: 我们可以通过下面一段代码探究run_simple() 方法都做了什么? from werkzeug.serving import run_simple from werkzeug.wrappers 阅读全文

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

2020年3月26日

python calendar模块

摘要: import calendar monthRange = calendar.monthrange(2018, 10) (0, 31) 输出的是一个元组; 第一个元素,数字0是这个月的第一天是星期天(上一个月的最后一天为星期几(0-6)),星期天为0; 第二个元素,数字31是这个月的天数; 阅读全文

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

上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 21 下一页

导航