finished iterators chapter

This commit is contained in:
Mark Pilgrim
2009-04-22 23:11:54 -04:00
parent 845ecdea10
commit 4afb4d3e69
6 changed files with 325 additions and 275 deletions
+4 -1
View File
@@ -1,11 +1,14 @@
"""Fibonacci iterator"""
class Fib:
"""iterator that yields numbers in the Fibanocci sequence"""
def __init__(self, max):
self.max = max
def __iter__(self):
self.a, self.b = 0, 1
self.a = 0
self.b = 1
return self
def __next__(self):
+3 -1
View File
@@ -15,8 +15,10 @@ def build_match_and_apply_functions(pattern, search, replace):
return (matches_rule, apply_rule)
class LazyRules:
rules_f = 'plural6-rules.txt'
def __init__(self):
self.pattern_file = open('plural6-rules.txt')
self.pattern_file = open(self.rules_f)
self.cache = []
def __iter__(self):