Deleting from a list (reprise)
Jason Orendorff
jason at jorendorff.com
Wed Jan 2 13:07:58 EST 2002
> 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.
The other runs, therefore, work with freqma=0.
Also: try this one. It's pretty quick.
def delcomp(sequence, marker):
sequence = [i for i in sequence if i != marker]
## Jason Orendorff http://www.jorendorff.com/
More information about the Python-list
mailing list