- 博客(7)
- 资源 (3)
- 收藏
- 关注
原创 code fragment Six from
>>> data = {}>>> data.get(cat, 1)1>>> data{}>>> data.setdefault(cat, 1)1>>> data{cat: 1}>>> data.setdefault(dog, []).append(2)>>> data{dog: [2], cat: 1}>>> data[bear] = 1 + data.get(b
2007-08-25 23:08:00 491
原创 code fragment Five from
"""Using dict to implement dispatch"""animals = []number_of_felines = 0def deal_with_a_cat(): global number_of_felines print "meow" animals.append(feline) number_of_felines += 1def dea
2007-08-25 22:39:00 547
原创 code fragment Four from
"""Given two dicts, find the set of keys that are in both dicts"""import timedef timeo(fun, n=1000): def void( ): pass start = time.clock( ) for i in range(n): void( ) stend = time.cl
2007-08-25 22:33:00 467
原创 code fragment Three from
"""unzip simple list-like obj"""def unzip(p, n): """ Example: >>> unzip([a,b,c,d,e], 3) [(a, d), (b, e), (c, None)] """ mlen, lft = divmod(len(p), n) if
2007-08-25 22:29:00 472
原创 code fragment Two from
"""List Comprehensions instead of map and filter"""theoldlist = range(10)thenewlist = map(lambda x: x+23, theoldlist)thenewlist2 = [x+23 for x in theoldlist]print thenewlist == thenewlist2thenewlist
2007-08-25 22:19:00 487
原创 code fragment One from
##########################################################"""Flattening a Nested Sequence"""from __future__ import generatorsdef flatten(sequence, scalarp, result=None): if result is None: result
2007-08-25 22:07:00 481
原创 ubuntu7.04下安装Apache2
总是提示错误:正在设置 apache (1.3.34-2ubuntu0.1) ...dpkg:处理 apache (--configure)时出错: 子进程·post-installation script·返回了错误号·10在处理时有错误发生: apacheE: Sub-process /usr/bin/dpkg returned an error code (1)百度了一下,没什么头绪,看到
2007-08-12 11:04:00 580
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人