Questions: While And List Comprehension

James Mills prologic at shortcircuit.net.au
Wed Nov 10 22:53:21 EST 2010


On Thu, Nov 11, 2010 at 11:01 AM, alex23 <wuwei23 at gmail.com> wrote:
> +1 on this approach. Clear and obvious and not reliant on any library
> modules other than sys.
>
> itertools, what WAS I thinking? :)

maybe:

import sys
from itertools import islice

print [v for v in islice((line for line in sys.stdin), 0, 5)]

?

-- 
-- James Mills
--
-- "Problems are solved by method"



More information about the Python-list mailing list