[Tutor] Array pointers

=?gb2312?q?=C9=F2=BD=E0=D4=AA?= orion_val at 163.com
Wed Jan 5 18:07:43 CET 2005


This code will work.

a=3D[1,0,0,0,0,1,1,1,0,1,1,0,1,0]

shorta=3Da[:]
while 0 in shorta:
    shorta.reverse()
    shorta.remove(0)
    shorta.reverse()
    print [0,]*(len(a)-len(shorta))+shorta
result=3D[0,]*(len(a)-len(shorta))+shorta


Juan Shen

=D4=DA 2005=C4=EA1=D4=C25=C8=D5 =D0=C7=C6=DA=C8=FD 11:44=A3=ACLiam Clarke =
=D0=B4=B5=C0=A3=BA
> Sorry rephrase -
>
> So I have a list -
>
> [0,0,0,0,0,1,1,1,0,1,1,0,1,0]
>
> I want to move all the 1's move to the right, 1 index at a time,
> preserving any spacing.
>
> i.e.
>
> [1,0,0,0,0,1,1,1,0,1,1,0,1,0]
>
> [0,1,0,0,0,0,1,1,1,0,1,1,0,1]
>
> [0,0,1,0,0,0,0,1,1,1,0,1,1,1]
>
> [0,0,0,1,0,0,0,0,1,1,1,1,1,1]
>
> [0,0,0,0,1,0,0,0,1,1,1,1,1,1]
>
> [0,0,0,0,0,1,0,0,1,1,1,1,1,1]
>
> [0,0,0,0,0,0,1,0,1,1,1,1,1,1]
>
> [0,0,0,0,0,0,0,1,1,1,1,1,1,1]
>
>
> Now, I have a whole list of these lists.... and I create an array of them.
> Is there a way to apply these changes wholescale without a large
> calculation time?
>
> I'm starting to think I'm going to have to go Cpp for this kind of
> direct pixel tweaking stuff.
> (640x480 (let alone 1024x768) is a lot of pixels to run through a for...
> loop)
>
> So yeah, anyone had this before?
>
> Regards,
>
> Liam Clarke
>



More information about the Tutor mailing list