def sort(self,key):
"""
This method modifies the sorting of the dictionary overriding the existing sort key.
:param key: it can be a sequence containing all the keys already existing in the dictionary
or a callable providing a sorting key algorithm.
"""
import operator
if operator.isCallable(key):
self._keys = sorted(self._keys,key=key)
else:
for k in self._keys:
if k not in self._keys: raise KeyError(k)
self._keys = list(key)
return self._keys[:]
评论列表
文章目录