Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'example:': 0.03; 'algorithm': 0.03; 'nested': 0.07; 'suppose': 0.07; 'tom': 0.07; 'iterate': 0.09; 'cc:addr:python-list': 0.10; 'wrote:': 0.17; 'variable': 0.20; 'received:209.85.214.174': 0.21; 'subject:problem': 0.22; 'cheers,': 0.23; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In- Reply-To:1': 0.25; 'values': 0.26; 'wondering': 0.26; 'realize': 0.27; 'message-id:@mail.gmail.com': 0.27; 'this?': 0.28; 'initial': 0.28; "i'm": 0.29; 'received:google.com': 0.34; 'sequence': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'but': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'things': 0.38; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; '10,000': 0.65; 'august': 0.66; 'subject:looking': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=G6GmgQLr+YzK1iuUBCRB98nsX02HP82rqQPEh0qoOlI=; b=QOtNM/9kcxU7CIo4f+RmBNQZSf6RQZQx54p2B3a5FnqH/MGnimLXiu25UKMJdJsPV4 QMHlUdGkkudQ3ghQDNXgD05xR6nNf8d+e82gqPAojs9iuySG54GtyhHea1D1mOJEYoW5 52Y//UGBoEhksJZ4pQa8D4DyObHk2G/xCzY75hmtimnJrUka1W7EEPS5DWXJn8eOJuFz ECeECk5sPGmlU2A2apQcp7Lx/U5QEWHBSapHfReSx2/hvMsTs5q7kgjY6ophMXzUbxcy z2arw+TkST6xeOBkO6PK+nwmngMN8Cj+P54TREwN0fhlwBStxq5mblAPQrjo3v8yatcv yRWg== MIME-Version: 1.0 In-Reply-To: References: Date: Mon, 6 Aug 2012 21:14:25 +0100 Subject: Re: looking for a neat solution to a nested loop problem From: Arnaud Delobelle To: Tom P Content-Type: text/plain; charset=UTF-8 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1344284069 news.xs4all.nl 6908 [2001:888:2000:d::a6]:45264 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26654 On 6 August 2012 16:52, Tom P wrote: > consider a nested loop algorithm - > > for i in range(100): > for j in range(100): > do_something(i,j) > > Now, suppose I don't want to use i = 0 and j = 0 as initial values, but some > other values i = N and j = M, and I want to iterate through all 10,000 > values in sequence - is there a neat python-like way to this? I realize I > can do things like use a variable for k in range(10000): and then derive > values for i and j from k, but I'm wondering if there's something less > clunky. For example: for i in range(100): for j in range(100): do_something((i + N)%100, (j + N)%100) Cheers, -- Arnaud