Ticket #3993: sorted_dict.diff

File sorted_dict.diff, 1.4 KB (added by Paul Collier <paul@…>, 18 years ago)
  • django/utils/datastructures.py

     
    7373    def items(self):
    7474        return zip(self.keyOrder, self.values())
    7575
     76    def iteritems(self):
     77        for key in self.keyOrder:
     78            yield key, dict.__getitem__(self, key)
     79
    7680    def keys(self):
    7781        return self.keyOrder[:]
    7882
     83    def iterkeys(self):
     84        return iter(self.keyOrder)
     85
    7986    def values(self):
    8087        return [dict.__getitem__(self, k) for k in self.keyOrder]
    8188
     89    def itervalues(self):
     90        for key in self.keyOrder:
     91            yield dict.__getitem__(self, key)
     92
    8293    def update(self, dict):
    8394        for k, v in dict.items():
    8495            self.__setitem__(k, v)
     
    92103        "Returns the value of the item at the given zero-based index."
    93104        return self[self.keyOrder[index]]
    94105
     106    def insert(self, index, key, value):
     107        "Inserts the key, value pair before the item with the given index."
     108        if key in self.keyOrder:
     109            n = self.keyOrder.index(key)
     110            del self.keyOrder[n]
     111            if n < index: index -= 1
     112        self.keyOrder.insert(index, key)
     113        dict.__setitem__(self, key, value)
     114
    95115    def copy(self):
    96116        "Returns a copy of this object."
    97117        # This way of initializing the copy means it works for subclasses, too.
Back to Top