Hi Folks,<div><br></div><div>I am quite new to python and I don't have a lot of experience with it yet.</div><div><br></div><div>I have two simple questions:</div><div><br></div><div>1. Is there a way to limit the number of times a list comprehension will execute? E.g. I want to read from input only 5 values, so I would like something like (the values between # # are what I want):</div>

<div>===================================================================================</div><div>COUNT = 0</div><div>print [ v for v in sys.stdin.readlines() <b># </b>IF COUNT < 5<b> #</b> ] ## Increment COUNT somewhere</div>

<div>===================================================================================</div><div><br></div><div>2.<b> </b>I would like to know another way, a more pythonic way, to write the following:</div><div>===================================================================================</div>

<div><div>import sys</div><div><br></div><div>def Z(iNumber):</div><div>    sum=0</div><div>    while (iNumber>=5):</div><div>        iNumber=iNumber/5</div><div>        sum = sum + iNumber</div><div>    print sum</div>

<div><br></div><div><div>def factorialCountZeros2():</div><div>    sysStdinReadLine = sys.stdin.readline</div><div>    numValues = int(sysStdinReadLine())</div><div>    [ Z(int(sysStdinReadLine())) for x in xrange(numValues) ]</div>

<div><br></div><div>if __name__ == '__main__':</div><div>    factorialCountZeros2()</div><div>===================================================================================</div><div>To be more specific, I would like to know about the Z function, is there a way to rewrite that while with list comprehension?</div>

<div><br></div><div>This code is to solve the CodeChef problem: <a href="http://www.codechef.com/problems/FCTRL/">http://www.codechef.com/problems/FCTRL/</a> (I am still in the easy part) and it executed in 2.5 secs, I would like to know if there is something else I can improve performance.</div>

<div><br></div><div>Thanks for your attention!</div><div><br></div><div>Regards,</div><div>Felipe.</div></div></div>