itertools.groupby
Steve Howell
showell30 at yahoo.com
Sun May 27 21:12:15 EDT 2007
--- Carsten Haese <carsten at uniqsys.com> wrote:
> [...] It's an abstract code pattern for an abstract
use
> case.
I question the use of abstract code patterns in
documentation, as they just lead to confusion. I
really think concrete examples are better in any
circumstance.
Also, to the OP's original contention, there is no way
that "uniquekeys" is a sensible variable in the overly
abstract example that is provided as an example in
the, er, non-examples portion of the documentation.
With the abstract non-example that's posted as an
example, the assertion of uniqueness implicit in the
name of the variable doesn't make any sense.
> There is an
> example on the following page, called Examples!
>
The example is useful. Thank you.
> > These docs need work. Please do not defend them;
>
> [...]
> To name just one, there's an example of
> itertools.groupby in the last
> code snippet at
>
http://informixdb.blogspot.com/2007/04/power-of-generators-part-two.html
>
Do we now, or could we, link to this example from the
docs?
> [...] that shouldn't stop you from suggesting
improvements.
>
I already did in a previous reply.
To repeat myself, I think a concrete example is
beneficial even on the main page:
import itertools
syslog_messages = [
'out of file descriptors',
'out of file descriptors',
'unexpected access',
'out of file descriptors',
]
for message, messages in
itertools.groupby(syslog_messages):
print message, len(list(messages))
...produces this...
out of file descriptors 2
unexpected access 1
out of file descriptors 1
____________________________________________________________________________________
Expecting? Get great news right away with email Auto-Check.
Try the Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/newmail_tools.html
More information about the Python-list
mailing list