Re: xslice idea | a generator slice

2013-07-11 Thread Ian Kelly
On Thu, Jul 11, 2013 at 1:58 PM, Fábio Santos wrote: > Isn't all of itertools implemented in C? If we are not using a python-level > and not-so-fast __getitem__ I would wager the C version is a lot faster. > > And if the input is indexable could I assume that it is not too large to > have around i

Re: xslice idea | a generator slice

2013-07-11 Thread Fábio Santos
On 11 Jul 2013 17:38, "Oscar Benjamin" wrote: > > On 11 July 2013 17:21, Russel Walker wrote: > > To confess, this is the second time I've made the mistake of trying to implement generator like functionality of a builtin when there already is on in itertools. Need to start studying that module ab

Re: xslice idea | a generator slice

2013-07-11 Thread Ian Kelly
On Thu, Jul 11, 2013 at 10:34 AM, Oscar Benjamin wrote: > On 11 July 2013 17:21, Russel Walker wrote: >> To confess, this is the second time I've made the mistake of trying to >> implement generator like functionality of a builtin when there already is on >> in itertools. Need to start studying

Re: xslice idea | a generator slice

2013-07-11 Thread Oscar Benjamin
On 11 July 2013 17:21, Russel Walker wrote: > To confess, this is the second time I've made the mistake of trying to > implement generator like functionality of a builtin when there already is on > in itertools. Need to start studying that module abit more I think. I'm > looking at the docs now

Re: xslice idea | a generator slice

2013-07-11 Thread Russel Walker
> > def __init__(self, seq, *stop): > > > > Wouldn't it be better if it has the same signature(s) as itertools.islice? That's actually what I was going for, except I was modeling it after range, but that was the only way I knew to implement it. > > if len(stop) > 3: > > >

Re: xslice idea | a generator slice

2013-07-11 Thread Ian Kelly
On Thu, Jul 11, 2013 at 8:52 AM, Russel Walker wrote: > Just some dribble, nothing major. > > I like using slices but I also noticed that a slice expression returns a new > sequence. > > I sometimes find myself using them in a for loop like this: > > > seq = range(10) > for even in seq[::2]: >

Re: xslice idea | a generator slice

2013-07-11 Thread Oscar Benjamin
On 11 July 2013 15:54, Russel Walker wrote: > ...oh and here is the class I made for it. > > class xslice(object): > ''' > xslice(seq, start, stop, step) -> generator slice > ''' > > def __init__(self, seq, *stop): Wouldn't it be better if it has the same signature(s) as itertools

xslice idea | a generator slice

2013-07-11 Thread Russel Walker
Just some dribble, nothing major. I like using slices but I also noticed that a slice expression returns a new sequence. I sometimes find myself using them in a for loop like this: seq = range(10) for even in seq[::2]: print even (That's just for an example) But wouldn't it be a bit of a

Re: xslice idea | a generator slice

2013-07-11 Thread Russel Walker
...oh and here is the class I made for it. class xslice(object): ''' xslice(seq, start, stop, step) -> generator slice ''' def __init__(self, seq, *stop): if len(stop) > 3: raise TypeError("xslice takes at most 4 arguments") elif len(stop) < 0: