Questions: While And List Comprehension
James Mills
prologic at shortcircuit.net.au
Wed Nov 10 18:01:37 EST 2010
On Wed, Nov 10, 2010 at 10:36 PM, Felipe Vinturini
<felipe.vinturini at 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"
More information about the Python-list
mailing list