newbie/ merging lists of lists with items in common
Neil Cerutti
horpner at yahoo.com
Fri Feb 2 10:14:29 EST 2007
On 2007-02-02, Laurent Pointal <laurent.pointal at limsi.fr> wrote:
> Neil Cerutti a écrit :
>> On 2007-02-02, ardief <rachele.defelice at gmail.com> wrote:
><zip>
>
>> This is a job for... duhn-duhn-DAAAAH! Captain CHAOS!
>>
>> Er... I mean itertools.groupby.
>>
><zip>
>> def key_func(t):
>> return t[0]
>
> Not needed: --> from operator import itemgetter
I agree. But I used it anyway, to make it easier to see that the
sort and the groupby must be and are using the same key function.
In this case I admit it's a not a huge readability win, but I was
also following the "Do Not Repeat Yourself Rule", which makes the
key function easier to refactor.
> See in the example:
> http://docs.python.org/lib/itertools-example.html
>
> So much stuff in libraries, so few we know. Thanks to doc
> writers, Usenet contributors & Google search engines.
Yup.
--
Neil Cerutti
More information about the Python-list
mailing list