Deleting from a list (reprise)
Jason Orendorff
jason at jorendorff.com
Wed Jan 2 17:39:17 EST 2002
> > Also: try this one. It's pretty quick.
> >
> > def delcomp(sequence, marker):
> > sequence = [i for i in sequence if i != marker]
> >
>
> This doesn't modify sequence, but creates a new one within the function.
>
> It'll work if you add 'return sequence' and invoke it as
> sequence=delcomp(sequence,marker)
Yes, but it's just a benchmark. We don't care about the result
except that the algorithm must be correct.
## Jason Orendorff http://www.jorendorff.com/
More information about the Python-list
mailing list