On Sep 25, 9:55 pm, Mark Summerfield <[EMAIL PROTECTED]>
wrote:
> ...
> class sorteddict(dict):
>
> ...
>         if self.__keys is None:
>             self.__keys = sorted(dict.keys(self), cmp=self.__cmp,
>                                  key=self.__key,
> reverse=self.__reverse)

You'd be better defining __keys like this:

def __getkeys(self):
  if self.__keycache is None:
     self.__keycache = dict.keys(self)
     self.__keycache.sort(cmp=...)
  return self.__keycache

__keys = property(__getkeys)

and where you have 'self.__keys = None', either replace with
'self.__keycache = None' or more cleanly with a call to:

def __invalidate_key_cache(self):
    self.__keycache = None

to improve the code quality.

--
Paul Hankin

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to