python - How do I return (or print) a maximum number of hits from a statement? -


i have loop statement returns umpteen million amount of numbers (ok exagerating bit :). how tell stop @ 50th result?

seams simple enough. can't find solution though. can't use lot of modules see being used here. in basic math module restricted in can use. if possible please elementary in answer. thank you

using python.

e.g. range(0, 99999999) or f = 's' * 50000000

.. print 50 results of these two.

you can use enumerate give index along value in loop. though i'm using lists here, i'm assuming using kind of iterator, otherwise slice list mylist[:50]. e.g., print 50th entry.

for i, val in enumerate(range(600)):     if == 50:         break     print 

or print every 50 values

for i, val in enumerate(range(600), start=1):     if % 50 == 0:         print val 

you use while loop too.

i = 0 some_iterator = iter(range(600)) while < 50:     print some_iterator.next()     += 1 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -