Ticket #5744: sorted_dict__init_tuples.diff

File sorted_dict__init_tuples.diff, 1.3 KB (added by Thomas Güttler <hv@…>, 7 years ago)
  • tests/regressiontests/datastructures/tests.py

     
    5555>>> print repr(d)
    5656{'one': 'not one', 'two': 'two', 'three': 'three'}
    5757
     58Init 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
    5866### DotExpandedDict ############################################################
    5967
    6068>>> d = DotExpandedDict({'person.1.firstname': ['Simon'], 'person.1.lastname': ['Willison'], 'person.2.firstname': ['Adrian'], 'person.2.lastname': ['Holovaty']})
  • django/utils/datastructures.py

     
    5454    def __init__(self, data=None):
    5555        if data is None: data = {}
    5656        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]
    5861
    5962    def __setitem__(self, key, value):
    6063        dict.__setitem__(self, key, value)
Back to Top