Note that there are some explanatory texts on larger screens.

plurals
  1. POWriting numbers from 0 to 1000000000
    primarykey
    data
    text
    <p>I am trying to write a list of the numbers from 0 to 1000000000 as strings, directly to a text file. I would also like each number to have leading zeros up to ten digit places, e.g. <code>0000000000, 0000000001, 0000000002, 0000000003, ... n.</code> However I find that it is taking much too long for my taste. </p> <p>I can use <code>seq</code>, but there is no support for leading zeros and I would prefer to avoid using <code>awk</code> and other auxiliary tools to handle these tasks. I am aware of dramatic speed-up benefits just from coding this in C, but I don't want to resort to it. I was considering mapping some functions to a large list and executing them in a loop, however I only have 2GB of RAM available, so please keep this in mind when approaching my problem. </p> <p>I am using <a href="http://code.google.com/p/python-progressbar/" rel="nofollow">Python-Progressbar</a>, and I am getting an ETA of approximately 2 hours. I would appreciate it if someone can offer me some advice as to how to approach this problem:</p> <pre><code>pbar = ProgressBar(widgets=[Percentage(), Bar(), ' ', ETA(), ' ', FileTransferSpeed()], maxval=1000000000).start() with open('numlistbegin','w') as numlist: limit, nw, pu = 1000000000, numlist.write, pbar.update for x in range(limit): nw('%010d\n'%(x,)) pu(x) pbar.finish() </code></pre> <p>EDIT: So I have discovered that the formatting (regardless of what programming language you are using), creates vast amounts of overhead. <code>Seq</code> gets the job done quickly, but much more slowly with the formatting option (-f). However, if anyone would like to offer a python solution nonetheless, it would be most welcome.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload