Ticket #5744: sorted_dict__init_tuples.diff
File sorted_dict__init_tuples.diff, 1.3 KB (added by , 17 years ago) |
---|
-
tests/regressiontests/datastructures/tests.py
55 55 >>> print repr(d) 56 56 {'one': 'not one', 'two': 'two', 'three': 'three'} 57 57 58 Init from sequence of tuples 59 >>> d = SortedDict(( 60 ... (1, "one"), 61 ... (0, "zero"), 62 ... (2, "two"))) 63 >>> print repr(d) 64 {1: 'one', 0: 'zero', 2: 'two'} 65 58 66 ### DotExpandedDict ############################################################ 59 67 60 68 >>> d = DotExpandedDict({'person.1.firstname': ['Simon'], 'person.1.lastname': ['Willison'], 'person.2.firstname': ['Adrian'], 'person.2.lastname': ['Holovaty']}) -
django/utils/datastructures.py
54 54 def __init__(self, data=None): 55 55 if data is None: data = {} 56 56 dict.__init__(self, data) 57 self.keyOrder = data.keys() 57 if isinstance(data, dict): 58 self.keyOrder = data.keys() 59 else: 60 self.keyOrder=[key for key, value in data] 58 61 59 62 def __setitem__(self, key, value): 60 63 dict.__setitem__(self, key, value)