On Wed, Nov 10, 2010 at 10:36 PM, Felipe Vinturini <felipe.vintur...@gmail.com> wrote: > 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): > =================================================================================== > COUNT = 0 > print [ v for v in sys.stdin.readlines() # IF COUNT < 5 # ] ## Increment > COUNT somewhere > ===================================================================================
print [v for v in sys.stdin.readlines()[:5]] cheers James -- -- James Mills -- -- "Problems are solved by method" -- http://mail.python.org/mailman/listinfo/python-list