Steven D'Aprano wrote:
> Can you sketch an O(n) algorithm for removing multiple items from an
> array, which *doesn't* involving building a temporary new list?
Here's what I meant. Have read/write indexes, delete the gap after maxcount
occurrences:
def remove(lst, value, maxcount):
read =
Chris Angelico wrote:
> On Sun, Dec 26, 2021 at 11:32 AM Jeremiah Vivian
> nohackingofkrow...@gmail.com wrote:
> > Steven D'Aprano wrote:
> > On Thu, Dec 23, 2021 at 05:53:46PM -, Stefan Pochmann wrote:
> > Chris Angelico wrote:
> > If you're removing multiple, it's usually best to filter.
On Sun, Dec 26, 2021 at 11:32 AM Jeremiah Vivian
wrote:
>
> Steven D'Aprano wrote:
> > On Thu, Dec 23, 2021 at 05:53:46PM -, Stefan Pochmann wrote:
> > > Chris Angelico wrote:
> > > If you're removing multiple, it's usually best to filter. This is a
> > > great opportunity to learn about list
Steven D'Aprano wrote:
> On Thu, Dec 23, 2021 at 05:53:46PM -, Stefan Pochmann wrote:
> > 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²) :)
> >
On Sun, Dec 26, 2021 at 11:00 AM Steven D'Aprano wrote:
>
> On Thu, Dec 23, 2021 at 05:53:46PM -, Stefan Pochmann wrote:
> > 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
> > >
On 2021-12-25 23:52, Steven D'Aprano wrote:
On Thu, Dec 23, 2021 at 05:53:46PM -, Stefan Pochmann wrote:
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
On Thu, Dec 23, 2021 at 05:53:46PM -, Stefan Pochmann wrote:
> 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
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,
> When called with the count argument, should it raise ValueError if there
> are fewer than `count` occurrences of the element in the list?
No, it shouldn't. It would raise ValueError if the element is not found within
the list though.
___
Python-ideas
On 2021-12-22 01:53, Rob Cliffe via Python-ideas wrote:
Currently list.remove raises ValueError if the element is not in the list.
When called with the count argument, should it raise ValueError if there
are fewer than `count` occurrences of the element in the list?
There's str.replace and
Currently list.remove raises ValueError if the element is not in the list.
When called with the count argument, should it raise ValueError if there
are fewer than `count` occurrences of the element in the list?
Best wishes
Rob Cliffe
On 22/12/2021 00:09, Jeremiah Vivian wrote:
I expect some
On Wed, Dec 22, 2021 at 11:12 AM Jeremiah Vivian
wrote:
>
> I expect some sort of "there's no benefit in this, just write the current
> implementation", indirectly or directly.
> Currently, this is the way to remove `num` occurrences of an element from a
> list:
> > idx = 0
> > while idx <
12 matches
Mail list logo