diff --git a/gramps/gui/views/treemodels/flatbasemodel.py b/gramps/gui/views/treemodels/flatbasemodel.py index 6b138e82d..9f8793d04 100644 --- a/gramps/gui/views/treemodels/flatbasemodel.py +++ b/gramps/gui/views/treemodels/flatbasemodel.py @@ -398,9 +398,14 @@ class FlatNodeMap(object): insert_pos = bisect.bisect_left(self._index2hndl, srtkey_hndl) self._index2hndl.insert(insert_pos, srtkey_hndl) #make sure the index map is updated - for hndl, index in self._hndl2index.items(): - if index >= insert_pos: - self._hndl2index[hndl] += 1 + if sys.version_info[0] < 3: # keep this, for speed in Python2 + for hndl, index in self._hndl2index.iteritems(): # in Python2 "if" + if index >= insert_pos: + self._hndl2index[hndl] += 1 + else: + for hndl, index in self._hndl2index.items(): + if index >= insert_pos: + self._hndl2index[hndl] += 1 self._hndl2index[srtkey_hndl[1]] = insert_pos #update self.__corr so it remains correct if self._reverse: @@ -442,9 +447,14 @@ class FlatNodeMap(object): if self._reverse: self.__corr = (len(self._index2hndl) - 1, -1) #update the handle2path map so it remains correct - for key, val in self._hndl2index.items(): - if val > index: - self._hndl2index[key] -= 1 + if sys.version_info[0] < 3: # keep this, for speed in Python2 + for key, val in self._hndl2index.iteritems(): # in Python2 "if" + if val > index: + self._hndl2index[key] -= 1 + else: + for key, val in self._hndl2index.items(): + if val > index: + self._hndl2index[key] -= 1 return Gtk.TreePath((delpath,)) #-------------------------------------------------------------------------