[Tutor] Can we unroll a loop?

Tino Dai oberoc at gmail.com
Mon Nov 2 21:52:43 CET 2009


Hi Everybody,

     I am wondering about a better approach to doing this:

     for obj in groups:
       rVs = rVs + Event.objects.get(group=obj)
    rVs.sort()

     Instead what I'm looking for is to have a construct that would expand
out to this:

    rVs =  Event.objects.get(group=groups[0]) |
Event.objects.get(group=groups[1]) \
            | ... | Event.objects.get(group=groups[n-1]) |
Event.objects.get(group=groups[n])

     I don't know if this is even possible. I have looked at the built in
map function as well as
some of the itertools functions, but nothing seems to fit the bill. Is this
even possible and
if so, how?

Thanks in advance!
-Tino
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091102/d4a7d909/attachment.htm>


More information about the Tutor mailing list