随笔分类 -  Idiomatic Python

My personal Idiomatic Python handbook
摘要:An Python implementation of heap-sortbased on the detailed algorithm description in Introduction to Algorithms Third Editionimport randomdef max_heap... 阅读全文
posted @ 2015-02-25 21:54 Justin.cn 阅读(250) 评论(0) 推荐(0)
摘要:1 a = range(3)2 b = range(3)3 [ (x, y) for x, y in zip(a, b) ]结果:1 [ (0,0), (1,1), (2,2) ]当然,如上可以推广到多个列表。 阅读全文
posted @ 2015-02-21 17:56 Justin.cn 阅读(2382) 评论(0) 推荐(0)
摘要:递归定义很简单,效率当然很低下,且极易超出栈空间大小.这样做纯粹是为了体现python的语言表现力而已, 并没有任何实际意义。1 def fib(x):2 return fib(x-1) + fib(x-2) if x - 2 > 0 else 1 阅读全文
posted @ 2015-02-18 01:04 Justin.cn 阅读(200) 评论(0) 推荐(0)
摘要:方法一:1 import operator2 3 def average(*args):4 return reduce(operator.add, args) / len(args) if args else 0注释:语句 if []: / if (): / if '' : / if {}:... 阅读全文
posted @ 2015-02-16 09:51 Justin.cn 阅读(203) 评论(0) 推荐(0)