Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Denis McMahon Newsgroups: comp.lang.python Subject: Re: A bug? Date: Wed, 29 Oct 2014 02:17:27 +0000 (UTC) Organization: A noiseless patient Spider Lines: 25 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Wed, 29 Oct 2014 02:17:27 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="66ffcfa4470a58bcddbdcd1913f98ab4"; logging-data="18390"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5Tw4H234nUwWDc2ito3tfg8V46j8Wp4A=" User-Agent: Pan/0.136 (I'm far too busy being delicious; GIT 926a150 git://git.gnome.org/pan2) Cancel-Lock: sha1:uANVpTc064TwDIm8Reo9MYxqA9I= Xref: csiph.com comp.lang.python:79869 On Tue, 28 Oct 2014 01:29:28 +0000, Joshua Landau wrote: > On 28 October 2014 00:36, Denis McMahon > wrote: >> >> d = [[list(range(1,13))[i*3+j] for j in range(3)] for i in range(4)] > > A quick note. Ranges (even 2.7's xrange) are all indexable. The cast to > a list isn't needed. Until you apply Chris' slicing trick, and then: >>> [list(range(1,13))[i*3:i*3+3] for i in range(4)] [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] >>> [range(1,13)[i*3:i*3+3] for i in range(4)] [range(1, 4), range(4, 7), range(7, 10), range(10, 13)] >>> Depends how important it is that you get a list and not a range object ;) (Thinking back to a recent discussion where someone was taking str(range (x)) and not getting the expected results) -- Denis McMahon, denismfmcmahon@gmail.com