Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #44160

Re: Running simultaneuos "FOR" loops

References <CAFqGZRGmNj1Hsedz0j8aHw+0UN+a+RDOFNUd1fU2v22T5VyhGg@mail.gmail.com> <51762FEC.4080603@islandtraining.com>
Date 2013-04-23 12:48 +0530
Subject Re: Running simultaneuos "FOR" loops
From inshu chauhan <insideshoes@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.960.1366701488.3114.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Running simultaneuos "FOR" loops inshu chauhan <insideshoes@gmail.com> - 2013-04-23 12:48 +0530

csiph-web