Ticket #3993: sorted_dict.diff
File sorted_dict.diff, 1.4 KB (added by , 18 years ago) |
---|
-
django/utils/datastructures.py
73 73 def items(self): 74 74 return zip(self.keyOrder, self.values()) 75 75 76 def iteritems(self): 77 for key in self.keyOrder: 78 yield key, dict.__getitem__(self, key) 79 76 80 def keys(self): 77 81 return self.keyOrder[:] 78 82 83 def iterkeys(self): 84 return iter(self.keyOrder) 85 79 86 def values(self): 80 87 return [dict.__getitem__(self, k) for k in self.keyOrder] 81 88 89 def itervalues(self): 90 for key in self.keyOrder: 91 yield dict.__getitem__(self, key) 92 82 93 def update(self, dict): 83 94 for k, v in dict.items(): 84 95 self.__setitem__(k, v) … … 92 103 "Returns the value of the item at the given zero-based index." 93 104 return self[self.keyOrder[index]] 94 105 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 95 115 def copy(self): 96 116 "Returns a copy of this object." 97 117 # This way of initializing the copy means it works for subclasses, too.