Deleting from a list (reprise)
Alex Martelli
aleax at aleax.it
Wed Jan 2 17:17:15 EST 2002
On Wednesday 02 January 2002 19:07, Jason Orendorff wrote:
> > def delwhile(sequence, marker):
> > sequence[:] = sequence
> > while marker in sequence: sequence.remove(marker)
>
> I think you mean
> sequence = sequence[:] # make a copy of 'sequence'
>
> What you wrote splices the list into itself (basically a no-op),
> with the result that the original sequence is modified in-place.
Ooops -- yes. I definitely DID intend a copy to be taken!-)
Alex
More information about the Python-list
mailing list