Running simultaneuos "FOR" loops
inshu chauhan
insideshoes at gmail.com
Tue Apr 23 03:18:06 EDT 2013
Thanks Gary.
>
> Be clearer about the problem please.
>
> Do you wish to produce a loop that:
> On pass 1, each of p,k, and t hold the first item of their respective
> lists, and
> on pass 2, each of p,k, and t hold the second item of their respective
> lists, and
> so on
> until one (or all) lists run out?
>
Yes this is excatly what I want each loop holds the first item on each
pass.
>
> If that is what you want, then check out the zip builtin function. But
> also consider this: Do you care what happens if one list runs out before
> the others?
>
Yes, but all dictionaries have same number of items.
>
> Or is it something else you want? Perhaps nested loops?
> for p in sorted(segments.iterkeys()):
> for k in sorted(class_count.iterkeys()):
> for j in sorted(pixel_count.iterkeys()):
> # This will be run with all possible combinations of p,k, and
> t
>
No, I know about nested loops but I dont want that because all the loops
have same number of items, inner loops will run out earlier.
>
> Gary Herron
>
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130423/a1dca7b4/attachment.html>
More information about the Python-list
mailing list