extract multiple ranges from a list

Paul Hankin paul.hankin at gmail.com
Sat Mar 8 16:42:01 CET 2008


On Mar 8, 3:28 pm, pi.arc... at gmail.com wrote:
> Hi guys,
>
> One of my many project involves working with YUV-files, where I need
> to reduce
> the vertical resolution with a factor of two, i.e. remove every other
> scan line.
> Today I'm using two for-loops in the fashion shown below
>
> y = []
> for i in range(0, width*height, width*2):
>     for j in range(0,width):
>         y.append(Y[i+j])

There's nothing really wrong with your code. Maybe it's a little nicer
written like this:

y = []
for i in range(0, height, 2):
    y.extend(Y[i * width + j] for j in range(width))

--
Paul Hankin



More information about the Python-list mailing list