[ZPT] tal:repeat over the sorted keys of a dictionary

Tino Wildenhain tino at wildenhain.de
Fri Jul 25 15:07:02 EDT 2003


Hi Jean,

Jean Jordaan wrote:
> .. the subject says it all. I want to do something like:
> 
>        <ul tal:define="keys licenses/keys; sortedkeys keys/sort"
>            tal:repeat="key sortedkeys">
>            <li tal:content="python:licenses[key]" />
>        </ul>
> 
> Unfortunately, "keys/sort" (and "python:keys.sort()") return None.
> What am I missing?
> 

sort() is an in-place operation.
In your python script which calculates the dictionary,
just do something like that:

sl=licenses.keys()
sl.sort()
return [licenses[key] for key in sl]


and use
  <ul>
    <li tal:repeat="license here/licensesscript" 
tal:content="license">dummy</li>
</ul>

In ZPT




More information about the ZPT mailing list