随笔分类 - 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...
阅读全文
摘要: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) ]当然,如上可以推广到多个列表。
阅读全文
摘要:递归定义很简单,效率当然很低下,且极易超出栈空间大小.这样做纯粹是为了体现python的语言表现力而已, 并没有任何实际意义。1 def fib(x):2 return fib(x-1) + fib(x-2) if x - 2 > 0 else 1
阅读全文
摘要:方法一:1 import operator2 3 def average(*args):4 return reduce(operator.add, args) / len(args) if args else 0注释:语句 if []: / if (): / if '' : / if {}:...
阅读全文
浙公网安备 33010602011771号