Path: csiph.com!usenet.pasdenom.info!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.110 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.78; '*S*': 0.00; 'subject:question': 0.10; 'times,': 0.14; '24,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterating': 0.16; 'once.': 0.16; 'index': 0.16; 'wrote:': 0.18; 'requirement.': 0.24; 'header :In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'produces': 0.31; 'provided,': 0.31; 'fri,': 0.33; 'maybe': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'library.': 0.36; 'sequence': 0.36; 'subject:Simple': 0.36; 'should': 0.36; 'list': 0.37; 'easiest': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'short': 0.38; 'to:addr:python.org': 0.39; 'most': 0.60; 'tell': 0.60; 'more': 0.64; 'different': 0.65; 'taking': 0.65; 'obvious': 0.74; 'idiot': 0.84; '2013': 0.98 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 :content-type:content-transfer-encoding; bh=cC2ncbDZ4KtDTh/70nE8zoGjLwUSv6wlVjAzZk6OaPE=; b=m23sRjT3ao+PjQUmZhC0YypRzD+76tLwHAtG20L8T356yi2NASxXhM385ao1Kv4afK jncx76PglLqC+ShJO5Xn9MxWtAuKx967yFHtlmpXtl8ELaIo38Pin3ZZwXYGuw4LT+gl cgGjSXeNG05x9oW3yJ3pYyeb2PU8CpdmWnvoCYpaIewFiSaGsh5vvL39K5eQ0vZvwSzH W06Q/1vyyO7yp7hlM+eGYzrM7bx5Qe/vcSeqMOIUAwD3puEiFlZbs+KWIK+JWC7rmY0U JayyeQmS3vyS7Bbj+I5Lxm92928V0brKyFEV95lt4g1+7DZa36P00Q5qgw4KZBI1s9vy frlw== MIME-Version: 1.0 X-Received: by 10.220.167.69 with SMTP id p5mr7798581vcy.57.1369386671148; Fri, 24 May 2013 02:11:11 -0700 (PDT) In-Reply-To: References: Date: Fri, 24 May 2013 19:11:11 +1000 Subject: Re: Simple algorithm question - how to reorder a sequence economically From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369387054 news.xs4all.nl 15976 [2001:888:2000:d::a6]:58857 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45873 On Fri, May 24, 2013 at 6:47 PM, F=E1bio Santos = wrote: > > On 24 May 2013 09:41, "Chris Angelico" wrote: >> >> On Fri, May 24, 2013 at 6:14 PM, Peter Brooks >> wrote: >> > What is the easiest way to reorder a sequence pseudo-randomly? >> > >> > That is, for a sequence 1,2,3,4 to produce an arbitrary ordering (eg >> > 2,1,4,3) that is different each time. >> > > ... > >> It works, it produces a unique list for any given index provided, but >> it's not the cleanest or most efficient. But I know someone'll improve >> on it... or tell me I'm an idiot for not taking a more obvious >> approach :) >> >> ChrisA > > I think that is pretty much itertools.permutations from the standard > library. The OP should check it out. That works if all the permutations are wanted at once. Is there a way, short of iterating over it N times, to request permutation #N? Or maybe I'm misreading the OP and that's not a requirement. ChrisA