[Python-ideas] Allow popping of slices

Michael Selik mike at selik.org
Fri Jun 8 20:03:05 EDT 2018

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 could 
> write 
>     for item in items.pop_all(): 
>         ... 
>         items.append(...) 
>         ... 

Isn't it equally easy to write:

    def foo(x):

    items = [foo(x) for x in items]

I don't understand the desire to write this as a loop over a 
``items.pop(slice(None))``. You can simply use the same loop body, 
replacing the ``for x in items:`` with ``def blah(x):`` and 
``items.append(y)`` with ``return y``. Low typing effort.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180608/4f91d0bd/attachment.html>

More information about the Python-ideas mailing list