Thank you very much!! I know my code needs to be tidied up xD. I'vd tried many 
things to solve the problem that's why my code looks so awful. And I'm glad 
there is an easy solution for my problem (and I didn't saw it *wall*)

And @bruno desthuilliers: It's good for a newbie like me to see how others 
would solve the problem. I will look if there is something I can do better.


Django has such a grea community. Thanks to everyone!


On So., 14. Aug. 2011 22:51:13 CEST, Jonas H. <jo...@lophus.org> wrote:

> 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.
> 

-- 
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