Grouping pairs - suggested tools

Ian Kelly ian.g.kelly at gmail.com
Tue Sep 21 08:49:48 CEST 2010


On Tue, Sep 21, 2010 at 12:19 AM, Alf P. Steinbach /Usenet <
alf.p.steinbach+usenet at gmail.com <alf.p.steinbach%2Busenet at gmail.com>>wrote:

> Uhm, thinking about it (it must have been my unconscious mind doing the
> work, it just popped into my head), if you first sort each individual
> equivalence relation so that you never have e.g. C=A but only A=C and so on,
> and then sort the list of equivalences, then it should reduce to walking the
> list and just starting a new set whenever a symbol is encountered that isn't
> yet in a set.
>

This won't work for all inputs.  Consider the input: [('a', 'd'), ('b',
'c'), ('c', 'd')]

Expected Output:

1, a
1, b
1, c
1, d

Actual Output:

1, a
1, d
2, c
2, b
2, d

Cheers,
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100921/d869da3a/attachment.html>


More information about the Python-list mailing list