Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79817
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2014-10-27 19:13 -0700 |
| References | <f491d969-7405-4017-b9c4-e1cb52a70280@googlegroups.com> <m2mof5$hvh$2@dont-email.me> <b675d41f-b690-4bcc-a0b7-3310f61f39ce@googlegroups.com> <mailman.15247.1414459556.18130.python-list@python.org> |
| Message-ID | <90cc19d7-a888-49aa-8005-15903e031f4a@googlegroups.com> (permalink) |
| Subject | Re: A bug? |
| From | Rustom Mody <rustompmody@gmail.com> |
On Tuesday, October 28, 2014 6:56:10 AM UTC+5:30, Chris Angelico wrote: > On Tue, Oct 28, 2014 at 12:12 PM, Rustom Mody wrote: > > More generally for d being a 2-D reshape of dd (which may be anything > > as long as the size matches) > > > >>>> dd = [1,2,3,4,5,6,7,8,9,10,11,12] > >>>> d=[[dd[i*3+j] for j in range(3)] for i in range(4)] > >>>> d > > [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] > > The inner comprehension should surely be a slice: > > >>> [dd[i*3:i*3+3] for i in range(4)] > [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] Sweet! [Something for my class today] Looks even better this way: >>> dd = range(1,13) >>> [dd[i*3:i*3+3] for i in range(4)] [range(1, 4), range(4, 7), range(7, 10), range(10, 13)] >>> In the same vein a transpose: >>> [list(dd[i::3]) for i in range(3)] [[0, 3, 6, 9], [1, 4, 7, 10], [2, 5, 8, 11]] [Not sure why both are 3; no 4's...]
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
A bug? "umatrp@gmail.com" <trsexgl@gmail.com> - 2014-10-27 09:01 -0700
Re: A bug? Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2014-10-27 17:17 +0100
Re: A bug? Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-27 10:26 -0600
Re: A bug? Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-28 00:36 +0000
Re: A bug? Rustom Mody <rustompmody@gmail.com> - 2014-10-27 18:12 -0700
Re: A bug? Chris Angelico <rosuav@gmail.com> - 2014-10-28 12:25 +1100
Re: A bug? Rustom Mody <rustompmody@gmail.com> - 2014-10-27 19:13 -0700
Re: A bug? Joshua Landau <joshua@landau.ws> - 2014-10-28 01:29 +0000
Re: A bug? Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-29 02:17 +0000
What for -- for? (was A bug?) Rustom Mody <rustompmody@gmail.com> - 2014-10-28 20:22 -0700
Re: What for -- for? (was A bug?) Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-10-28 23:16 -0500
Re: What for -- for? (was A bug?) Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-10-28 23:23 -0500
Re: What for -- for? (was A bug?) Rustom Mody <rustompmody@gmail.com> - 2014-10-28 21:40 -0700
Re: What for -- for? (was A bug?) Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-10-28 23:59 -0500
Re: What for -- for? (was A bug?) Rustom Mody <rustompmody@gmail.com> - 2014-10-28 22:15 -0700
Re: What for -- for? (was A bug?) Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-10-29 00:39 -0500
Re: What for -- for? (was A bug?) Rustom Mody <rustompmody@gmail.com> - 2014-10-28 23:11 -0700
Re: What for -- for? (was A bug?) Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-10-29 01:18 -0500
Finding way around ABCs (was What for -- for? (was A bug?)) Rustom Mody <rustompmody@gmail.com> - 2014-10-30 10:01 -0700
Re: Finding way around ABCs (was What for -- for? (was A bug?)) Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-30 11:09 -0600
Re: Finding way around ABCs (was What for -- for? (was A bug?)) Rustom Mody <rustompmody@gmail.com> - 2014-10-30 10:16 -0700
Re: Finding way around ABCs (was What for -- for? (was A bug?)) Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-30 11:11 -0600
Re: What for -- for? (was A bug?) Ben Finney <ben+python@benfinney.id.au> - 2014-10-29 16:27 +1100
Re: What for -- for? (was A bug?) Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-10-29 00:42 -0500
Re: What for -- for? (was A bug?) Rustom Mody <rustompmody@gmail.com> - 2014-10-28 22:57 -0700
Re: What for -- for? (was A bug?) Ben Finney <ben+python@benfinney.id.au> - 2014-10-29 17:02 +1100
Re: What for -- for? (was A bug?) Joshua Landau <joshua@landau.ws> - 2014-10-30 17:21 +0000
Re: What for -- for? (was A bug?) Rustom Mody <rustompmody@gmail.com> - 2014-10-30 10:41 -0700
csiph-web