> <snipped>
>
>
>
> > fav_and_projs = ((f, f.project) for f in favourites)
>
> This may not be a Django question. But, I'm not familiar with this syntax.
> Is this returning a tuple for ever item in favourites? So, fav_and_projs
> would be a tuple of tuples, like ((f1, f.project1), (f2, fproject2),
> .....(fn, fprojectn))??
Actually, this is a generator that returns tuples. It doesn't really
make sense to think of it as a single datastructure - it's more like a
function that returns the next tuple each time you call .next() on it.
To be honest in this case I'd be more likely to use a simple list
expression:
[(f, f.project) for f in favourites]
which will return a list of tuples straight away, and doesn't need
separate evaluation. However this is inefficient if you have a large
list (of favourites) to begin with.
--
DR.
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment