Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52194

Re: Suggestion: PEP for popping slices from lists

References (1 earlier) <mailman.345.1375956533.1251.python-list@python.org> <531d89a8-61e1-4117-b4cc-f02b3be30bb9@googlegroups.com> <mailman.347.1375960376.1251.python-list@python.org> <9bd6192b-2c71-4662-808a-fd7e74dedeb8@googlegroups.com> <62769807-dff7-40a0-a060-d1e0b7c0685f@googlegroups.com>
Date 2013-08-08 14:08 +0100
Subject Re: Suggestion: PEP for popping slices from lists
From Nicholas Cole <nicholas.cole@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.350.1375967296.1251.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Thu, Aug 8, 2013 at 12:50 PM, Neatu Ovidiu <neatuovi@gmail.com> wrote:

> On Thursday, August 8, 2013 2:44:05 PM UTC+3, Neatu Ovidiu wrote:
> > On Thursday, August 8, 2013 2:12:53 PM UTC+3, Nicholas wrote:
> >
> > > On Thu, Aug 8, 2013 at 11:38 AM, Neatu Ovidiu <neat...@gmail.com>
> wrote:
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> > > > But what's your use case?
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > Does it occur often enough that you cannot afford a two-liner like
> >
> > >
> >
> > > I think uses cases are plenty.
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> > > The possible cases I can think of would be better served with list
> comprehensions (what you seem to want is to create lists based on other
> lists) - but maybe I'm missing something.  Could we have one example?
> >
> > >
> >
> > >
> >
> > >
> >
> > > N.
> >
> >
> >
> > 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', 'job4', 'job5', 'job6', 'job7', 'job8',
> 'job9', 'job10']
> >
> > while jobs:
> >
> >     print(jobs.pop_slice(0,4))
> >
> >
> >
> > should output
> >
> >
> >
> > 'job1', 'job2', 'job3', 'job4'
> >
> > 'job5', 'job6', 'job7', 'job8'
> >
> > 'job9', 'job10'
>
> The idea "popped" in my mind while thinking about this question.
>
> http://stackoverflow.com/questions/18121416/right-split-a-string-into-groups-of-3/18122084
> I founded the list comprehensions solutions kind of cumbersome and thought
> that there should be a simple way to do this kind of stuff.
> --
> http://mail.python.org/mailman/listinfo/python-list
>


Still seems a bit like a solution looking for a problem to me.

Why would you want to take four items at a time for a job from an arbitrary
part of a list?  I agree splitting a string into groups of three looks a
bit cumbersome in the example you've given, but a generator could be
written quite easily, and would almost certainly be quicker than trying to
alter the list in place.

Best wishes,

N.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Suggestion: PEP for popping slices from lists Neatu Ovidiu Gabriel <neatuovi@gmail.com> - 2013-08-08 02:45 -0700
  Re: Suggestion: PEP for popping slices from lists Peter Otten <__peter__@web.de> - 2013-08-08 12:07 +0200
    Re: Suggestion: PEP for popping slices from lists Neatu Ovidiu <neatuovi@gmail.com> - 2013-08-08 03:38 -0700
      Re: Suggestion: PEP for popping slices from lists Nicholas Cole <nicholas.cole@gmail.com> - 2013-08-08 12:12 +0100
        Re: Suggestion: PEP for popping slices from lists Neatu Ovidiu <neatuovi@gmail.com> - 2013-08-08 04:40 -0700
          Re: Suggestion: PEP for popping slices from lists Skip Montanaro <skip@pobox.com> - 2013-08-08 09:20 -0500
        Re: Suggestion: PEP for popping slices from lists Neatu Ovidiu <neatuovi@gmail.com> - 2013-08-08 04:44 -0700
          Re: Suggestion: PEP for popping slices from lists Neatu Ovidiu <neatuovi@gmail.com> - 2013-08-08 04:50 -0700
            Re: Suggestion: PEP for popping slices from lists Nicholas Cole <nicholas.cole@gmail.com> - 2013-08-08 14:08 +0100
              Re: Suggestion: PEP for popping slices from lists Neatu Ovidiu <neatuovi@gmail.com> - 2013-08-08 06:32 -0700
                Re: Suggestion: PEP for popping slices from lists Nicholas Cole <nicholas.cole@gmail.com> - 2013-08-08 15:03 +0100
          Re: Suggestion: PEP for popping slices from lists Terry Reedy <tjreedy@udel.edu> - 2013-08-08 16:03 -0400
          Re: Suggestion: PEP for popping slices from lists Joshua Landau <joshua@landau.ws> - 2013-08-08 22:32 +0100
          Re: Suggestion: PEP for popping slices from lists Tim Chase <python.list@tim.thechases.com> - 2013-08-08 16:50 -0500
          Re: Suggestion: PEP for popping slices from lists Terry Reedy <tjreedy@udel.edu> - 2013-08-08 18:10 -0400

csiph-web