Suggestion: PEP for popping slices from lists

Skip Montanaro skip at pobox.com
Thu Aug 8 10:20:58 EDT 2013


On Thu, Aug 8, 2013 at 6:40 AM, Neatu Ovidiu <neatuovi at gmail.com> wrote:
> This can be useful for doing all kinds of basic stuff. For example if you wanted to take 4 items of a list at at a time, do something with them and then update the list.
>
> jobs = ['job1', 'job2', 'job3', 'job5', 'job6', 'job7', 'job8', 'job9', 'job10']
> while jobs:
>     print jobs.pop_slice(0,4)

My initial reaction to this is that you want to infer structure where
none exists, so why not make the structure explicit?  In any case,
couldn't you subclass the list type and add a pop_slice method to do
what you want?  I'm not an iterator maven, but this also seems like
something you could mix up from something in the itertools module.

Skip



More information about the Python-list mailing list