How to sort very large arrays?
rentlong at gmail.com
Sat Jun 14 09:19:17 CEST 2008
On Jun 14, 1:54 am, kj <so... at 987jk.com.invalid> wrote:
> I'm downloading some very large tables from a remote site. I want
> to sort these tables in a particular way before saving them to
> disk. In the past I found that the most efficient way to do this
> was to piggy-back on Unix's highly optimized sort command. So,
> from within a Perl script, I'd create a pipe handle through sort
> and then just print the data through that handle:
This is a python clone of your code from a python rookie :)
from os import popen
p = popen("sort -t '\t' -k1,1 -k2,2 -u > %s" % out_file)
for line in data:
print >> p, line
there is no "die $!" here, I think it is good to let python
throw the exception to your console
> open my $out, "|$sort -t '\t' -k1,1 -k2,2 -u > $out_file" or die $!;
> print $out $_ for @data;
> But that's distinctly Perlish, and I'm wondering what's the "Python
> Way" to do this.
> NOTE: In my address everything before the first period is backwards;
> and the last period, and everything after it, should be discarded.
More information about the Python-list