On Thu, Aug 8, 2013 at 2:32 PM, Neatu Ovidiu <neatu...@gmail.com> wrote:
> On Thursday, August 8, 2013 4:08:13 PM UTC+3, Nicholas wrote: > > On Thu, Aug 8, 2013 at 12:50 PM, Neatu Ovidiu <neat...@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. > > You are perfectly right. But I looked at it more like an improvement in > the style of writing solutions and also a natural option because slices are > highly present all over in python. > I wasn't knocking it. I was just trying to think it through.
-- http://mail.python.org/mailman/listinfo/python-list