Comparing a lot of data efficiently

Ignacio Vazquez-Abrams ignacio at openservices.net
Mon Aug 27 12:22:31 CEST 2001


On Mon, 27 Aug 2001, Ignacio Vazquez-Abrams wrote:

> If you can't guarantee that they're in the same order, then you'll have to
> create some sort of class to hold the three tuples and return a value from
> __hash__() that will be the same when the three nodes are in any order, but
> not for nodes that have different values.

Or you can put them in lists, sort them, and then convert the list to a tuple:

>>> a=[(1,2,3),(7,5,9),(4,8,6)]
>>> a.sort()
>>> tuple(a)
((1, 2, 3), (4, 8, 6), (7, 5, 9))

I hate it when I realize a better solution after I send the e-mail ;)

-- 
Ignacio Vazquez-Abrams  <ignacio at openservices.net>





More information about the Python-list mailing list