Fast sorting many lists together...?
Mike Fletcher
mfletch at tpresence.com
Fri Sep 15 14:16:54 EDT 2000
Hmm, you might try something like...
tuples = apply( map, (None, )+tuple( list-of-lists) )
# tuples is now a list of "records"
tuples.sort()
Then just pull the columns back out again with a for loop. You'd put
list-of-lists in the order you want the keys to sort, so primary key first,
then secondary, etc. That's only 25000 new tuples, which I would think
would be fairly fast on most machines.
Alternately, just do a map(None, keycol, range(len(keycol))) to get key,
index tuples, then sort that and use a for loop to pick the indices out of
each column.
HTH,
Mike
-----Original Message-----
From: William Park [mailto:parkw at better.net]
Sent: Friday, September 15, 2000 1:41 PM
To: python-list at python.org
Subject: Fast sorting many lists together...?
Hi,
I need to sort about 50 lists (each about 500 elements) together, using few
of them as keys. That is, sort the key lists first; look at which indexes
have changed; then, shuffle the rest of list to reflect this new order.
Does anyone know a fast fast routine for doing this?
---William Park, Open Geometry Consulting
--
http://www.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list