Ahh thanks Bruno, that gave the correct solution:

>>> l
['pos 0', 'pos 1', 'pos 2', 'pos 3']
>>> l[1::2]
['pos 1', 'pos 3']

My slice-fu is clearly weak.

Cheers

Tom

On Thu, Dec 9, 2010 at 12:03 PM, bruno desthuilliers
<bruno.desthuilli...@gmail.com> wrote:
>
>
> On 9 déc, 12:24, Tom Evans <tevans...@googlemail.com> wrote:
>> Hmm, those are the values that are odd, he wanted the values from odd
>> indices
>
> Well spotted ;)
>
> There's a builtin "slice" filter that should have done the trick but I
> just couldn't manage to make it work with a for loop :-/
>
> The only solution I could come with that does not require custom
> filters or whatever is using the cycle tag (http://
> docs.djangoproject.com/en/1.2/ref/templates/builtins/#cycle):
>
> {% for item in list %}
>  {% cycle "even", "odd"  as oddeven %} {# assuming standard 0-based
> indexing #}
>  {% if oddeven == "odd" %}
>    <p>item {{ item }} is at odd index {{ forloop.counter }}</p>
>  {% endif %}
> {% endfor %}
>
>
> NB : not tested...
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to