3 ms·
Not bad, however with the ''.join(data) you're effectively doubling the amount of memory needed for large files, because it will build the entire output string
by benhoyt 13y ago
Not bad, however with the ''.join(data) you're effectively doubling the amount of memory needed for large files, because it will build the entire output string in memory (and you've already got the list in memory). Better to use writelines(). You can also use sorted() to iterate over and sort the input lines automatically:
sorted_lines = sorted(open(sys.argv[1]))
open(sys.argv[2]).writelines(sorted_lines)