Deleting from a list (reprise)
aleax at aleax.it
Wed Jan 2 23:17:15 CET 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!-)
More information about the Python-list