Mercurial > public > think_complexity
diff ch3ex4.py @ 14:bc2c07a059be
Completing Ch 3.3, exercise 4.2.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 10 Dec 2012 19:58:03 -0600 |
parents | be7f2cd15faf |
children |
line wrap: on
line diff
--- 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