I have a browser view method which returns an OrderedDict containing at most 18 brains, originated by something similar to this:
mydict = OrderedDict()
for b in brains:
video_obj = b.getObject()
mydict[b] = {'video_id': video_obj.url,
'thumb': video_obj.tag(scale='thumb')}
return mydict
I can easily loop through them generating a flat UL > LI list in ZPT:
<ul>
<li tal:repeat="brain mydict">
<a tal:attributes="href python:mydict[brain]['video_id']">
<img tal:replace="mydict[brain]['thumb']" />
</a>
</li>
</ul>
But what I want is a batch-like structure:
<ul>
<li>
<a>Item 1</a>
<a>Item 2</a>
<a>Item 3</a>
</li>
...
<li>
<a>Item 16</a>
<a>Item 17</a>
<a>Item 18</a>
</li>
</ul>
Eg: I'd like to transform this {1:2, 2:4, 3:6, 4:8, 5:10, 6:12, 7:14, 8:16, 9:18} into this [{1:2, 2:4, 3:6}, {4:8, 5:10, 6:12}, {7:14, 8:16, 9:18}].
I prefer not to change the browser view since other parts of the template expect mydict's keys to be brains.
BTW if I had a list instead of a dict I could regroup its elements with:
zip(*[mylist[i::3] for i in range(3)])
But that's not possible for dicts and (strangely imo) not for OrderedDicts either.
I think this is what you you really want: