On 07/03/07, Rob Andrews <[EMAIL PROTECTED]> wrote:
> I'm trying to think of the best way to go about this one, as the files
> I have to sort are *big*.
[...]
> I haven't yet figured out a way to apply sort() to this problem,
> although I'm certain the failing is my own.

To use sort(), you'll have to read the entire file or files into
memory first.  If you can do that, your procedure would be:
 1. Read into memory, splitting each file into a tuple.
 2. Use sort(key=operator.itemgetter(1))  (or whatever field you are sorting on)

If it's not practical to read the file into memory, perhaps you could
use a database?  You could download pysqlite, which is an embeddable
relational database.  Your procedure would then be:
 1. Create database, table, possibly indices on columns you're
interested in sorting by
 2. Read and parse files line by line, insert into database
 3. Run query 'select blah from foo order by whatever limit 50000'.

-- 
John.
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to