A bug?

Chris Angelico rosuav at gmail.com
Mon Oct 27 21:25:47 EDT 2014


On Tue, Oct 28, 2014 at 12:12 PM, Rustom Mody <rustompmody at gmail.com> 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]]

ChrisA



More information about the Python-list mailing list