intersection of 2 list of pairs
John Machin
sjmachin at lexicon.net
Tue Feb 22 18:30:21 EST 2005
bearophileH... at lycos.com wrote:
> The use of frozenset can okay when sub-sequences are longer, but for
> this problem it's slow, and anyway there are situations of repeated
> data like this that have to be considered:
Not just for frozenset; this has to be considered whatever the
representation.
>
> frozenset( ('a', 'a') )
> ==>
> frozenset(['a'])
>
> For Py2.4 the faster and better solution seems Peter Otten one.
> James Stroud solution is O(n^2) and it can become slow for long
> lists...
"Better"? In what sense? My point is that the OP's real problem
requires (a) a workable canonical representation of a pair -- lack of
this is most probably the root cause of the problem that he is trying
to solve!! -- and (b) a result that identifies the duplicate pairs
unambiguously so that he can do something with them.
"Faster"? The solutions proposed by Peter and James do more-or-less
answer the OP's ill-formed question, but speed should be the last
consideration, after the real problem is defined carefully.
More information about the Python-list
mailing list