This code will work. a=[1,0,0,0,0,1,1,1,0,1,1,0,1,0]
shorta=a[:] while 0 in shorta: shorta.reverse() shorta.remove(0) shorta.reverse() print [0,]*(len(a)-len(shorta))+shorta result=[0,]*(len(a)-len(shorta))+shorta Juan Shen 在 2005年1月5日 星期三 11:44,Liam Clarke 写道: > 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 > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor