Chris Angelico wrote:
> If you're removing multiple, it's usually best to filter. This is a
> great opportunity to learn about list comprehensions and the
> difference between O(n) and O(n²) :)
> ChrisA

It would be O(n) if done right. And could be much more efficient than a list 
comprehension, because:

1) The list's C code would do it.
2) It could stop comparing early.
3) It wouldn't have to touch the later elements (a list comp would, to 
increment ref counts).
4) Doesn't need to build a new list.

Also, how would you write it as a list comprehension? Trivial for removing 
*all* occurrences, but for removing only up to some count? I can do it, but 
it's not pretty.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/TBTHNS4M6EOLJ6YQOFNPWSNKVO3PP5CS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to