Jeff Watkins wrote:
> Jeremy, that's some seriously twisted code. Unfortunately, the
> presence of Nones in the result when the list isn't an even multiple
> of 3 means for even more Kidness. Because now I have to check whether
> the value is None or else I get an exception.
>
> For example:
>
> <?python
> i= iter(product_list)
> rows= map(None, i, i, i)
> ?>
> <table>
> <tr py:for="row in rows">
> <td py:for="product in row">
> <div py:if="product" py:strip="True">
> <h3>${product.title}</h3>
> <p>${product.description}</p>
> </div>
> </td>
> </tr>
> </table>
>
> True, it works. But it's a bit unpleasant that I need to explicitly
> check whether the value is None.
>
Can't you filter them out before the loop ?
rows=[filter(lambda x: x is not None, chunk) for chunk in
map(None,*[iter(a)]*3)]