Mercurial > public > think_complexity
changeset 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 | b163f18eaf92 |
files | ch3ex4.py |
diffstat | 1 files changed, 8 insertions(+), 3 deletions(-) [+] |
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