James Mills wrote: > On Thu, Nov 11, 2010 at 11:01 AM, alex23 <wuwe...@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)]
(line for line in sys.stdin) and sys.stdin are equivalent as are [v for v in items] and list(items) So print list(islice(sys.stdin, 5)) Peter -- http://mail.python.org/mailman/listinfo/python-list