[Zope-CMF] Sorting listFolderContents()

Tres Seaver tseaver@zope.com
12 Mar 2003 20:39:11 -0500


On Wed, 2003-03-12 at 20:21, Michael LaPera wrote:
> Hello,
> 
> I know this is probably a simple question, but I searched around and 
> can't seem to find the answer that I can understand.  I'm calling 
> listFolderContents() on a folderish object and I want to sort the 
> resulting object by there Titles.

Use what the Python Cookbook calls the DSU ("decorate-sort-undecorate")
pattern:

  contents = []

  for v in context.listFolderContents():
      contents.append( ( v.Title(), v ) )  # "decorate w/ sort key

  contents.sort()

  return [ x[1] for x in contents ]  # undecorate

Tres.
-- 
===============================================================
Tres Seaver                                tseaver@zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com