摘要: import re # 运算字典 calc = { '+': lambda x, y: x + y, # 加 '-': lambda x, y: x - y, # 减 '*': lambda x, y: x * y, # 乘 '/': lambda x, y: x / y, # 除 '%': lambda x, y: x % y, # 取余数 ... 阅读全文
posted @ 2017-03-12 21:19 破斧呈粥 阅读(335) 评论(0) 推荐(0) 编辑
摘要: #slist = [[i for i in range(4)] for l in range(8)] # slist = [ # [4, 5, 2, 7], # [8, 7, 4, 2], # [1, 9, 7, 3], # [0, 4, 5, 6], # ] # 4*4 slist = [ [4, 5, 2, 7], [8, 7, 4, 2... 阅读全文
posted @ 2017-03-12 18:41 破斧呈粥 阅读(201) 评论(0) 推荐(0) 编辑
摘要: # 在有序序列内查找,判断大于还是小于中间值,每次搜索减一半,直到达到退出条件 # 递归二分查找具体索引 def search(num, start, end, args): global m m += 1 middle = (start + end) // 2 # 整除取中间值 # print('start:%s , end:%s , middle:%s ... 阅读全文
posted @ 2017-03-12 18:37 破斧呈粥 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 日志格式 阅读全文
posted @ 2017-03-12 18:33 破斧呈粥 阅读(101) 评论(0) 推荐(0) 编辑
摘要: 日志格式 backend test.oldboy.orgb1 backend buy.oldboy.org 阅读全文
posted @ 2017-03-12 18:28 破斧呈粥 阅读(99) 评论(0) 推荐(0) 编辑
摘要: ''' # 不改变原函数代码,在调用原函数之前或之后执行其他代码 # 不加参数是两层def,会直接将原函数地址传递进来,返回new_fun(带原函数地址)下的inner函数 # 原函数执行前调用的函数(统一参数) # def new_fun(sfunc): # def inner(args): # # 新添加内容 # print('装饰符...') # ... 阅读全文
posted @ 2017-03-12 18:24 破斧呈粥 阅读(251) 评论(0) 推荐(0) 编辑
摘要: import re s = '3456fpeiuHa123@126.com' # 从开头匹配 ret = re.match('34', s) print(ret) # 找第一个 ret = re.search('56', s) print(ret) #替换 ret= re.sub('@','|',s) print(ret) # 匹配一个数字 ret = re.match('[0-9]'... 阅读全文
posted @ 2017-03-12 18:23 破斧呈粥 阅读(142) 评论(0) 推荐(0) 编辑
摘要: import time # 迭代器:通过next向后一次一次取值,不能向前,不能通过下标取值 tup = iter((1, 2, 3, 4, 5, 6)) lis = iter([11, 22, 33, 44, 55]) # 循环一次,相当于执行了一次__next__ for i in lis: print(i) # 生成器 def ggg(generator): whi... 阅读全文
posted @ 2017-03-12 18:21 破斧呈粥 阅读(112) 评论(0) 推荐(0) 编辑
摘要: #函数体内按条件,调用自己 #递归相除 def sal(x): n = x / 2 if n > 1: sal(n) print(n) sal(1000) # 斐波那契数 def fun1(a, b, lis=[]): if a 0: num -= 1 fun2(num) fun2(10) print(su... 阅读全文
posted @ 2017-03-12 18:20 破斧呈粥 阅读(167) 评论(0) 推荐(0) 编辑
摘要: import collections as con st = '1324243598234598756' tup = (4,67,7,5,6,67,78,8,4,2,2,4, 4,56,7,8,5,3,23,45,468,9,1,) lis = [1,4,5,7,8,2,2,1,56,7,89,34,2,3,4,5,6,5,8,7,4,12,1] # 计算序列某元素出现的次数 ... 阅读全文
posted @ 2017-03-12 18:19 破斧呈粥 阅读(155) 评论(0) 推荐(0) 编辑
摘要: import collections as con # 有序添加和取字典元素 ord = con.OrderedDict() ord['a'] = 1 ord['b'] = 2 ord['c'] = 3 print(ord, 'ordereddict') # 移动某元素到最后 ord.move_to_end('a') print(ord, 'move_to_end') 阅读全文
posted @ 2017-03-12 18:18 破斧呈粥 阅读(149) 评论(0) 推荐(0) 编辑
摘要: import collections as con #默认字典数据类型(参数填数据类型) dic = con.defaultdict(list) dic['a'].append(55) print(dic,'defaultdict') 阅读全文
posted @ 2017-03-12 18:17 破斧呈粥 阅读(149) 评论(0) 推荐(0) 编辑
摘要: import collections as con #用namedtyuple创建一个类 classtuple = con.namedtuple('classtuple', ['x', 'y', 'z']) #用这个类创建可命名元组对象 namet= classtuple(1,2,3) print 阅读全文
posted @ 2017-03-12 18:15 破斧呈粥 阅读(96) 评论(0) 推荐(0) 编辑
摘要: import collections as con dq = con.deque() # 右侧添加 dq.append(1) print(dq, 'append') # 左侧添加 dq.appendleft(2) print(dq, dq[0], 'appendleft') # 清空队列 # dq.clear() # 队列某元素数量 print(dq.count(1), 'count'... 阅读全文
posted @ 2017-03-12 18:12 破斧呈粥 阅读(111) 评论(0) 推荐(0) 编辑
摘要: import queue # 参数指定队列大小 q = queue.Queue(10) print(q) # 查看当前队列数量 print(q.qsize(), 'qsize') # 当前队列是否为空 print(q.empty()) #当前队列数量是否已达到队列最大值 print(q.full(),'full') #加入一个队列成员 q.put(10) q.put(1) print(... 阅读全文
posted @ 2017-03-12 18:11 破斧呈粥 阅读(114) 评论(0) 推荐(0) 编辑
摘要: import copy # 浅拷贝 # copy.copy() # 深拷贝 # copy.deepcopy() # 赋值 s1 = '1234' s2 = 456 t1 = s1 t2 = s2 c1 = copy.copy(s1) c2 = copy.deepcopy(s1) print(id(s1), id(t1), id(c1), id(c2), id(s2), id(t2)) #... 阅读全文
posted @ 2017-03-12 18:05 破斧呈粥 阅读(151) 评论(0) 推荐(0) 编辑
摘要: # 无参数 def fun1(): print(1, '无参数') fun1() # 带返回值 def fun2(): return 999 print(fun2(), '带返回值') # 有参数 def fun3(a, b): print(a, b, '带参数') fun3(1, 3) # 默认参数 def fun4(a, b=333): print... 阅读全文
posted @ 2017-03-12 18:03 破斧呈粥 阅读(557) 评论(0) 推荐(0) 编辑
摘要: ''' abs() dict() help() min() setattr() all() dir() hex() next() slice() any() divmod() id() object() sorted() ascii() enumerate() input() oct() staticmethod() bin() eval() int() open() str() bool() ... 阅读全文
posted @ 2017-03-12 18:01 破斧呈粥 阅读(136) 评论(0) 推荐(0) 编辑