On Mon, Oct 22, 2018 at 7:58 AM Terry Reedy <tjre...@udel.edu> wrote: > > An indefinite number of in-place removes is a generally a bad idea > unless done carefully. > alist.remove is inherently O(n). > alist.removeall implemented naively would be O(n*n)/ > alist = [x for x in alist if x == old] or > alist = list(x for x in alist if x == old) or > alist = list(filter(lambda x: x == old)) is O(n). >
That's actually a good reason to make it part of the language or stdlib - it's very easy to get it wrong. All of the above are not in-place. If I were to make a stdlib function to do removeall, it would be: seq[:] = [x for x in seq if x != removeme] (And that one probably missed some subtlety somewhere too.) So it'd be less buggy for people to reach for a standard solution than to try to craft their own. That said, though, I think this probably belongs as a recipe, not as a stdlib function or method. ChrisA _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/