04 2013 档案

摘要:dict设置默认值 “” A common use of dictionaries is to count occurrences by setting the value of d[key] to 1 on its first occurrence, then increment the value on each subsequent occurrence. This can be done several different ways, but the get() method is the most succinct: ”“” ... 阅读全文
posted @ 2013-04-16 18:29 tangr206 阅读(302) 评论(0) 推荐(0)
摘要:参考:http://www.ibm.com/developerworks/cn/opensource/os-cn-python-yield/http://blog.shine-it.net/python/dive-into-generator您可能听说过,带有 yield 的函数在 Python 中被称之为 generator(生成器),何谓 generator ?我们先抛开 generator,以一个常见的编程题目来展示 yield 的概念。清单 1. 简单输出斐波那契數列前 N 个数 def fab(max): n, a, b = 0, 0, 1 while n <... 阅读全文
posted @ 2013-04-09 20:05 tangr206 阅读(1625) 评论(0) 推荐(0)