how to delete multiple elements from a list

etsang at etsang at
Wed Nov 15 23:25:57 CET 2000

Hi I have another question: What if List Y is something like:
(1,2,3,6,7,8) and List X is (0,1,2,3,4,5,6,7)
When List Y is in deceding order:

for each iteration of for loop, List X will have one element deleted.
But after element 3 is deleted, List X no longer has element in
postions 8,7, or 6.
hoe can I write the code so that I do not have any restriction on what
List Y has????

In article <uaoQ5.24146$U46.888647 at>,
  "Greg Jorgensen" <gregj at> wrote:
> <etsang at> wrote in message news:8usjl6
$vea$1 at
> > I have a List X with N number of items in it. I have another List Y
> > which contains the postion of the elements to be deleted from List
> > I cannot do a for loop to delete that because for each iteration,
> > X will be changed and there will be sliperage.
> >
> > How can I delete all the items as specified by the positions in Y at
> > one time? Also both List X and List Y are known in run time only.
> > Thanks
> y.sort()
> y.reverse()
> for p in y:
>     try:
>         del x[p]
>     except IndexError:
>         pass
> --
> Greg Jorgensen
> Deschooling Society
> Portland, Oregon, USA
> gregj at

Sent via
Before you buy.

More information about the Python-list mailing list