Re: Candidate for a new itertool

2009-03-18 Thread George Sakkis
On Mar 7, 8:47 pm, Raymond Hettinger wrote: > The existing groupby() itertool works great when every element in a > group has the same key, but it is not so handy when groups are > determined by boundary conditions. > > For edge-triggered events, we need to convert a boundary-event > predicate to

Re: Candidate for a new itertool

2009-03-18 Thread Aahz
In article <6ca71455-2fb2-4dd0-a500-2a480d815...@v6g2000vbb.googlegroups.com>, Raymond Hettinger wrote: > >For edge-triggered events, we need to convert a boundary-event >predicate to groupby-style key function. The code below encapsulates >that process in a new itertool called split_on(). > >Wo

Re: Candidate for a new itertool

2009-03-12 Thread pruebauno
On Mar 7, 8:47 pm, Raymond Hettinger wrote: > The existing groupby() itertool works great when every element in a > group has the same key, but it is not so handy when groups are > determined by boundary conditions. > > For edge-triggered events, we need to convert a boundary-event > predicate to

Re: Candidate for a new itertool

2009-03-10 Thread pruebauno
On Mar 9, 6:55 pm, Raymond Hettinger wrote: > [prueba] > > > The data often contains objects with attributes instead of tuples, and > > I expect the new namedtuple datatype to be used also as elements of > > the list to be processed. > > > But I haven't found a nice generalized way for that kind o

Re: Candidate for a new itertool

2009-03-09 Thread Raymond Hettinger
[prueba] > The data often contains objects with attributes instead of tuples, and > I expect the new namedtuple datatype to be used also as elements of > the list to be processed. > > But I haven't found a nice generalized way for that kind of pattern > that aggregates from a list of one datatype t

Re: Candidate for a new itertool

2009-03-09 Thread pruebauno
On Mar 7, 8:47 pm, Raymond Hettinger wrote: > The existing groupby() itertool works great when every element in a > group has the same key, but it is not so handy when groups are > determined by boundary conditions. > > For edge-triggered events, we need to convert a boundary-event > predicate to

Re: Candidate for a new itertool

2009-03-09 Thread bearophileHUGS
Raymond Hettinger: >In your experiences with xsplit(), do most use cases involve removing the >separators?< Unfortunately I am not able to tell you how often I remove them. But regarding strings, I usually want to remove separators: >>> "aXcdXfg".split("X") ['a', 'cd', 'fg'] So sometimes I wan

Re: Candidate for a new itertool

2009-03-09 Thread Raymond Hettinger
On Mar 7, 7:58 pm, bearophileh...@lycos.com wrote: > Raymond Hettinger, maybe it can be useful to add an optional argument > flag to tell such split_on to keep the separators or not? This is the > xsplit I usually use: In your experiences with xsplit(), do most use cases involve removing the separ

Re: Candidate for a new itertool

2009-03-08 Thread jay logan
On Mar 7, 8:47 pm, Raymond Hettinger wrote: > The existing groupby() itertool works great when every element in a > group has the same key, but it is not so handy when groups are > determined by boundary conditions. > > For edge-triggered events, we need to convert a boundary-event > predicate to

Re: Candidate for a new itertool

2009-03-07 Thread bearophileHUGS
Raymond Hettinger, maybe it can be useful to add an optional argument flag to tell such split_on to keep the separators or not? This is the xsplit I usually use: def xsplit(seq, key=bool, keepkeys=True): """xsplit(seq, key=bool, keepkeys=True): given an iterable seq and a predicate key, s

Candidate for a new itertool

2009-03-07 Thread Raymond Hettinger
The existing groupby() itertool works great when every element in a group has the same key, but it is not so handy when groups are determined by boundary conditions. For edge-triggered events, we need to convert a boundary-event predicate to groupby-style key function. The code below encapsulates