On 08/14/2011 09:57 PM, bruno desthuilliers wrote:
{% for current, entry, month, n in months %}

Please think about what "months" is here... Yes, a list of dicts. So
this line is the equivalent of:

current = months[0] # first dict in the list
entry = months[1]    # second dict in the list
month = months[2]  # etc....
n = months[3]

It is not. If you define multiple loop variables, Python will unpack every item in the sequence into those variables -- so this code

    for a, b in [...]:
        ...

is equivalent to

    for item in [...]:
        a, b = item
        ...

or

    for item in [...]:
        a = item[0]
        b = item[0]
        ...

So what happens if your sequence is [{'foo': 1, 'bar': 2}]? The dict gets unpacked into the loop variables:

    for item in [{'foo': 1, 'bar': 2}]:
        a, b = item

And what happens if you loop over a dict? You get a sequence of keys. That's why in the OPs output, those keys will show up in the output.

@Schmidtchen: Use mlist.append([n+1, month, entry, current]) instead of a dict and you're done -- that also solves the ordering issue.

And Bruno, Schmidtchen's code might really need some cleanup but that's beyond the scope of this thread: You might have noticed that your comments did *not help* the OP fixing his issues *at all*.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@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