how to delete multiple elements from a list
Mikael Olofsson
mikael at isy.liu.se
Tue Nov 21 02:36:49 EST 2000
On 14-Nov-00 etsang at my-deja.com wrote:
> 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 X.
> I cannot do a for loop to delete that because for each iteration, List
> X will be changed and there will be sliperage.
You _can_ do that with a loop. Just make sure that you have Y in reverse
order.
Y.sort()
Y.reverse()
for y in Y:
del X[y]
> How can I delete all the items as specified by the positions in Y at
> one time?
I will leave that one to someone else.
HTH
/Mikael
-----------------------------------------------------------------------
E-Mail: Mikael Olofsson <mikael at isy.liu.se>
WWW: http://www.dtr.isy.liu.se/dtr/staff/mikael
Phone: +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
Date: 21-Nov-00
Time: 08:29:07
/"\
\ / ASCII Ribbon Campaign
X Against HTML Mail
/ \
This message was sent by XF-Mail.
-----------------------------------------------------------------------
More information about the Python-list
mailing list