# HG changeset patch # User Brian Neal # Date 1355191083 21600 # Node ID bc2c07a059be4b2f9c790d6813ad32d9c0e8a649 # Parent be7f2cd15faf86db535ce8680030a660735ba84a Completing Ch 3.3, exercise 4.2. diff -r be7f2cd15faf -r bc2c07a059be ch3ex4.py --- a/ch3ex4.py Mon Dec 10 19:42:38 2012 -0600 +++ b/ch3ex4.py Mon Dec 10 19:58:03 2012 -0600 @@ -61,6 +61,12 @@ m = self.find_map(k) return m.get(k) + def iteritems(self): + """Generator function to yield items in the map.""" + for lm in self.maps: + for t in lm.items: + yield t + class HashMap(object): """An implementation of a hashtable using a BetterMap @@ -92,9 +98,8 @@ """Makes a new map, twice as big, and rehashes the items.""" new_maps = BetterMap(self.num * 2) - for m in self.maps.maps: - for k, v in m.items: - new_maps.add(k, v) + for k, v in self.maps.iteritems(): + new_maps.add(k, v) self.maps = new_maps