mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 23:10:17 +00:00
finished iterators chapter
This commit is contained in:
@@ -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
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user