Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.076 X-Spam-Evidence: '*H*': 0.85; '*S*': 0.00; 'nested': 0.07; 'builtin': 0.09; 'runs': 0.10; 'cc:addr:python-list': 0.11; 'combinations': 0.16; 'dictionaries': 0.16; 'earlier.': 0.16; 'loops': 0.16; 'items.': 0.19; 'cc:addr:python.org': 0.22; '(or': 0.24; 'cc:2**0': 0.24; 'holds': 0.26; 'this:': 0.26; 'second': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'respective': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'gary': 0.31; 'please.': 0.31; 'lists': 0.32; 'run': 0.32; 'url:python': 0.33; 'problem': 0.35; 'skip:s 30': 0.35; 'something': 0.35; 'no,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'thanks': 0.36; 'possible': 0.36; 'url:org': 0.36; 'list': 0.37; 'subject:" ': 0.39; 'url:mail': 0.40; 'first': 0.61; 'zip': 0.64; 'dont': 0.67; 'yes': 0.68; 'wish': 0.70; 'clearer': 0.84; '\xa0\xa0\xa0\xa0\xa0': 0.84; 'items,': 0.91; 'subject:FOR': 0.91; '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=IsaKPWlAVZEk25k/POAj03gB7fcTbXQbdIUhiY2tJqY=; b=TxdO2G6ZnGKUl7KVGAc2Qp/N2i1d24rdxIstFmFwfzrPOew5mAiMYwBDFCLzcS5dq9 CXi+a2PlAcQao9r8udLqYtR/wlLpW9ycaDzT0qqYTEIqCm2Zb8DXsQDMIMVKzdiQi/wh MrHVM6NNa3bo2VfhxjPMj12mRNMIwBAMU6JvolnIIm2wUnkZGEE3zY4YytTO/s4LBpU/ E6p2o51Zc3bmgUFBci2BhNtaX2w0K+tQraaAkW9e0N6fpElUo81sgLqhxOlS3JAb5n6h VJFRruzwBVknqwOViH+TmqBCR1/cQwjEHhMqnmSYnsKqOBmk6w107y7QPkHVhEcw2v2U LFrg== MIME-Version: 1.0 X-Received: by 10.50.33.11 with SMTP id n11mr14164736igi.40.1366701486341; Tue, 23 Apr 2013 00:18:06 -0700 (PDT) In-Reply-To: <51762FEC.4080603@islandtraining.com> References: <51762FEC.4080603@islandtraining.com> Date: Tue, 23 Apr 2013 12:48:06 +0530 Subject: Re: Running simultaneuos "FOR" loops From: inshu chauhan To: Gary Herron Content-Type: multipart/alternative; boundary=089e0153873e9b83a804db01fc8a Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 115 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366701488 news.xs4all.nl 2266 [2001:888:2000:d::a6]:41841 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44160 --089e0153873e9b83a804db01fc8a Content-Type: text/plain; charset=ISO-8859-1 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 > > --089e0153873e9b83a804db01fc8a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Thanks Gary.=A0




Be clearer about the problem please.

Do you wish to produce a loop that:
=A0 On pass 1, each of p,k, and t hold the first item of their respective lists, and
=A0 on pass 2, each of p,k, and t hold the second item of their respective lists, and
=A0 so on
until one (or all) lists run out?

=
Yes this is excatly what I want each loop holds the first item o= n each pass. =A0

If that is what you want, then check out the zip builtin function.=A0 But also consider this:=A0 Do you care what happens if one list runs out before the others?=A0

Yes, but all dictionaries have same number of items.=A0

Or is it something else you want?=A0 Perhaps nested loops?
=A0 for =A0p in sorted(segments.iterkeys()):
=A0=A0=A0=A0=A0 for k in sorted(class_count.iterkeys()):
=A0=A0=A0=A0=A0=A0=A0=A0=A0 for j in sorted(pixel_count.iterkeys()): =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 # This will be run with all possib= le combinations of p,k, and t

No, I know about= nested loops but I dont want that because all the loops have same number o= f items, inner loops will run out earlier.=A0
=A0

Gary Herron





--
http://mail.python.org/mailman/listinfo/python-list


--089e0153873e9b83a804db01fc8a--