[Tutor] reducing a list evenly when deleting elements by index

Oscar Benjamin oscar.j.benjamin at gmail.com
Mon Sep 17 03:29:44 CEST 2012


On 17 September 2012 02:15, Pete O'Connell <pedrooconnell at gmail.com> wrote:

> Hi, I have a bezier line with 20 points on it and I am trying to reduce
> this to a line with 4 points, keeping the first and last points and 2
> evenly spaced points in between like so:
> *....................*
> becomes:
> *.     .      .     .*
>
> These points are removable only by index, so if I remove point 2,
> point 3 then becomes point 2 in the next iteration, so I end up having a
> spacing like this which is not what I want:
> *.          .     . .*


But removing item 19 doesn't affect the position of item 2. The trick is to
start the loop at the end of the list and work back to the beginning.

Oscar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120917/0b982ce7/attachment.html>


More information about the Tutor mailing list