Re: itertools.groupby



Gordon Airporte <JHoover@xxxxxxx> writes:
This is my first exposure to this function, and I see that it does
have some uses in my code. I agree that it is confusing, however.
IMO the confusion could be lessened if the function with the current
behavior were renamed 'telescope' or 'compact' or 'collapse' or
something (since it collapses the iterable linearly over homogeneous
sequences.)

It chops up the iterable into a bunch of smaller ones, but the total
size ends up the same. "Telescope", "compact", "collapse" etc. make
it sound like the output is going to end up smaller than the input.

There is also a dirty secret involved <wink>, which is that the
itertools functions (including groupby) are mostly patterned after
similarly named functions in the Haskell Prelude, which do about the
same thing. They are aimed at helping a similar style of programming,
so staying with similar names IMO is a good thing.

A function named groupby could then have what I think is the clearly
implied behavior of creating just one iterator for each unique type of
thing in the input list, as categorized by the key function.

But that is what groupby does, except its notion of uniqueness is
limited to contiguous runs of elements having the same key.
.



Relevant Pages

  • Re: Finding useful functions- part 1
    ... sometimes seems to apply to an input to a single neuron, ... it's compared to the desired outcome is confusing, at least to me, for ... since IMO an output is a signal to the experimenter, ... My comments as a pure outsider may or may not help clarify ...
    (sci.cognitive)
  • Re: Radio buttons and tabs
    ... > fwiw, imo 2 option buttons that are both set = False are confusing to the ... especially since, once the user sets one, there'll be no way for them ...
    (microsoft.public.vb.controls)
  • Re: Jet another feature
    ... Too many "operators" or other language constructs would be a lot more ... confusing, IMO. ... Rudy Velthuis ...
    (borland.public.delphi.non-technical)
  • Re: Jet another feature
    ... >> to operators will help better understanding. ... > confusing, IMO. ... If I wanted more complication, I would use C++ for development & refuse any ...
    (borland.public.delphi.non-technical)