On Thu, Nov 11, 2010 at 6:10 PM, Peter Otten <__pete...@web.de> wrote:
> (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))
I was being a little verbose ... But I like your simplification :)
c
On Thu, Nov 11, 2010 at 6:10 AM, Peter Otten <__pete...@web.de> wrote:
> James Mills wrote:
>
> > On Thu, Nov 11, 2010 at 11:01 AM, alex23 wrote:
> >> +1 on this approach. Clear and obvious and not reliant on any library
> >> modules other than sys.
> >>
> >> itertools, what WAS I thinking? :)
>
James Mills wrote:
> On Thu, Nov 11, 2010 at 11:01 AM, alex23 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 islic
On 10/11/10 22:56, Emile van Sebille wrote:
On 11/10/2010 4:36 AM Felipe Vinturini said...
Hi Folks,
I am quite new to python and I don't have a lot of experience with it
yet.
I have two simple questions:
1. Is there a way to limit the number of times a list comprehension will
execute? E.g. I
On Thu, Nov 11, 2010 at 3:05 PM, rantingrick wrote:
> Hey all you guys could be mistaken. It looks like the OP is trying to
> implement some sort of ghetto database. And he may NOT necessarily
> want the FIRST five lines of the file. He said (and i quote) "the
> values /between/ # and #". Where #
On Nov 10, 4:56 pm, Emile van Sebille wrote:
> On 11/10/2010 4:36 AM Felipe Vinturini said...
>
> > Hi Folks,
>
> > I am quite new to python and I don't have a lot of experience with it yet.
>
> > I have two simple questions:
>
> > 1. Is there a way to limit the number of times a list comprehensio
On Thu, Nov 11, 2010 at 11:01 AM, alex23 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)]
On Thu, Nov 11, 2010 at 1:02 PM, Steve Holden wrote:
> This suggests that you are mistaken about not exhausting the source.
Yeah I was mistaken. Oh well :) I was thinking of a generator-based
solution and got lost in the implementation!
--
-- James Mills
--
-- "Problems are solved by method"
--
On Thu, Nov 11, 2010 at 11:38 AM, MRAB wrote:
> 'list' will exhaust the input, then the slicing will return at most 5
> lines.
Hmm you're right :)
--
-- James Mills
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list
On 11/10/2010 4:36 AM Felipe Vinturini said...
> 2.* *I would like to know another way, a more pythonic way, to write the
> following:
> ===
> import sys
>
> def Z(iNumber):
> sum=0
> while (iNumber>=5):
>
On 11/10/2010 7:29 PM, James Mills wrote:
> On Thu, Nov 11, 2010 at 8:56 AM, Emile van Sebille wrote:
>> Easiest would be print [ v for v in sys.stdin.readlines()[:5] ] but that
>> still reads the entire sys.stdin (whatever it may be...)
>
> Here's a way of doing the same thing without consuming
On Wed, Nov 10, 2010 at 5:38 PM, MRAB wrote:
> On 11/11/2010 00:29, James Mills wrote:
>> On Thu, Nov 11, 2010 at 8:56 AM, Emile van Sebille wrote:
>>> Easiest would be print [ v for v in sys.stdin.readlines()[:5] ] but that
>>> still reads the entire sys.stdin (whatever it may be...)
>>
>> Here'
On 11/11/2010 00:29, James Mills wrote:
On Thu, Nov 11, 2010 at 8:56 AM, Emile van Sebille wrote:
Easiest would be print [ v for v in sys.stdin.readlines()[:5] ] but that
still reads the entire sys.stdin (whatever it may be...)
Here's a way of doing the same thing without consuming the entire
Steve Holden wrote:
> how about print [sys.stdin.readline() for i in range(5)]
>
> At least that won't consume the whole file.
+1 on this approach. Clear and obvious and not reliant on any library
modules other than sys.
itertools, what WAS I thinking? :)
--
http://mail.python.org/mailman/listi
On 11/10/2010 6:01 PM, James Mills wrote:
> On Wed, Nov 10, 2010 at 10:36 PM, Felipe Vinturini
> 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 # # ar
On Thu, Nov 11, 2010 at 8:56 AM, Emile van Sebille wrote:
> Easiest would be print [ v for v in sys.stdin.readlines()[:5] ] but that
> still reads the entire sys.stdin (whatever it may be...)
Here's a way of doing the same thing without consuming the entire
stream (sys.stdin):
#!/usr/bin/env pyt
On Wed, Nov 10, 2010 at 10:36 PM, Felipe Vinturini
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):
> ===
On 11/10/2010 4:36 AM Felipe Vinturini said...
Hi Folks,
I am quite new to python and I don't have a lot of experience with it yet.
I have two simple questions:
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
Hi Folks,
I am quite new to python and I don't have a lot of experience with it yet.
I have two simple questions:
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 # #
19 matches
Mail list logo