Re: [Python-ideas] Allow popping of slices

2018-06-08 Thread Michael Selik
On Tuesday, June 5, 2018 at 12:19:53 AM UTC-7, Ben Rudiak-Gould wrote: > > When the loop is simple enough I can write > > items = [... for item in items] > > and when it's complicated enough it probably makes sense to split it > into a separate function. But I've many times wished that I

Re: [Python-ideas] Allow popping of slices

2018-06-05 Thread Ben Rudiak-Gould
On Mon, Jun 4, 2018 at 5:11 PM, Steven D'Aprano wrote: > class MyList(list): > def pop(self, pos): > if isinstance(pos, slice): > temp = self[pos] > del self[pos] > return temp > return super().pop(pos) > > Is that what you have in mind?

Re: [Python-ideas] Allow popping of slices

2018-06-04 Thread Steven D'Aprano
On Mon, Jun 04, 2018 at 03:23:07PM -0700, Ben Rudiak-Gould wrote: > The `pop` method of built-in sequences is basically an atomic version of > > val = self[pos] > del self[pos] > return val Aside from the atomicness, for testing we can subclass list: # Untested class MyList(list):

[Python-ideas] Allow popping of slices

2018-06-04 Thread Ben Rudiak-Gould
The `pop` method of built-in sequences is basically an atomic version of val = self[pos] del self[pos] return val If this behavior was extended to the case where `pos` is a slice, you could write things like: def cut_deck(deck, pos): deck.extend(deck.pop(slice(0, pos)))