1.1 --- a/lib/__builtins__/dict.py Sat Feb 04 22:26:23 2017 +0100
1.2 +++ b/lib/__builtins__/dict.py Sun Feb 05 00:25:59 2017 +0100
1.3 @@ -40,13 +40,16 @@
1.4
1.5 # Implementation methods.
1.6
1.7 - def _find_entry(self, key, index):
1.8 + def _find_entry(self, buckets, key, index):
1.9
1.10 - "Search for 'key', using an 'index' identifying the bucket involved."
1.11 + """
1.12 + Search in 'buckets' for 'key', using an 'index' identifying the bucket
1.13 + involved.
1.14 + """
1.15
1.16 i = 0
1.17
1.18 - for found, value in self.buckets[index]:
1.19 + for found, value in buckets[index]:
1.20 if found == key:
1.21 return i
1.22 i += 1
1.23 @@ -68,7 +71,7 @@
1.24
1.25 "Set in the 'buckets' an item having the given 'key' and 'value'."
1.26
1.27 - index, i = self._get_entry(key)
1.28 + index, i = self._get_entry(buckets, key)
1.29
1.30 # With no existing entry, append to the bucket.
1.31
1.32 @@ -146,13 +149,13 @@
1.33 the dictionary, 'default' will be returned instead.
1.34 """
1.35
1.36 - index, i = self._get_entry(key)
1.37 + index, i = self._get_entry(self.buckets, key)
1.38
1.39 # With no entry index, either raise an exception or return the default.
1.40
1.41 if i is None:
1.42 if default is self.MISSING:
1.43 - raise KeyError(key)
1.44 + raise KeyError, key
1.45 else:
1.46 return default
1.47
1.48 @@ -182,9 +185,25 @@
1.49
1.50 return self._items()
1.51
1.52 - def setdefault(self, key, value): pass
1.53 + def setdefault(self, key, value):
1.54 +
1.55 + """
1.56 + Set for 'key' the given 'value' only if no entry for 'key' is already
1.57 + present. Return the associated value for 'key', which will either be the
1.58 + existing value already present in the dictionary or the supplied 'value'
1.59 + that was given to establish an entry in the dictionary.
1.60 + """
1.61
1.62 - def update(self, other): pass
1.63 + if not self.has_key(key):
1.64 + self[key] = value
1.65 + return self.get(key)
1.66 +
1.67 + def update(self, other):
1.68 +
1.69 + "Update this dictionary with the items from 'other'."
1.70 +
1.71 + for key, value in other.items():
1.72 + self[key] = value
1.73
1.74 def values(self):
1.75