> > [Steven Bethard]
> > > So do I read this right in preferring
> > > [ for in ]
> > > over
> > > list( for in )
[Raymond Hettinger]
> > Yes!
[Simon Brunning]
> Why? (Serious question. I'm sure that you have a good reason - I just
> can't figure out what it is.)
>
> The generator exp
Simon Brunning wrote:
> On Apr 5, 2005 2:04 AM, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
>> [Steven Bethard]
>> > So do I read this right in preferring
>> > [ for in ]
>> > over
>> > list( for in )
>>
>> Yes!
>
> Why? (Serious question. I'm sure that you have a good reason - I ju
On Apr 5, 2005 2:04 AM, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
> [Steven Bethard]
> > So do I read this right in preferring
> > [ for in ]
> > over
> > list( for in )
>
> Yes!
Why? (Serious question. I'm sure that you have a good reason - I just
can't figure out what it is.)
Th
> > Use a genexp when you need a generator
> > and use a listcomp when you need a list.
[Steven Bethard]
> So do I read this right in preferring
> [ for in ]
> over
> list( for in )
Yes!
Raymond
--
http://mail.python.org/mailman/listinfo/python-list
Raymond Hettinger wrote:
[Steven Bethard]
and I often find myself alternating
between the two when I can't decide which one seems more Pythonic.
Both are pythonic.
Use a genexp when you need a generator
and use a listcomp when you need a list.
So do I read this right in preferring
[ for in ]
o
[Steven Bethard]
> and I often find myself alternating
> between the two when I can't decide which one seems more Pythonic.
Both are pythonic.
Use a genexp when you need a generator
and use a listcomp when you need a list.
Raymond Hettinger
--
http://mail.python.org/mailman/listinfo/python-l
This is all just making everything far too complicated. What you really
want to do is quite simple:
import itertools
def condition(x): return x < 5
list(itertools.takewhile(condition, (i for i in range(10
The 'Stop Iteration In Generator Expression' problem was solved in the
language that Li
Raymond Hettinger wrote:
[Peter Otten]
Do you see any chance that list comprehensions will be redefined as an
alternative spelling for list()?
Not likely. It is possible that the latter spelling would make it possible
for
Py3.0. eliminate list comps entirely. However, they are very popular and
p
[Peter Otten]
> Do you see any chance that list comprehensions will be redefined as an
> alternative spelling for list()?
Not likely. It is possible that the latter spelling would make it possible for
Py3.0. eliminate list comps entirely. However, they are very popular and
practical, so my bet i
jfj wrote:
>> To make it a bit clearer, a StopIteration raised in a generator
>> expression silently terminates that generator:
>
> *any* exception raised from a generator, terminates the generator
Yeah, but StopIteration is the only expected exception and therefore the
only one that client code
Raymond Hettinger wrote:
(quoting Bengt)
>> I assumed that all standard sequence consumers (including list, of
>> course) would intercept the StopIteration of a sequence given them in the
>> form of a generator expression, so your lyst example would have an
>> analogue for other sequence consumer
> I assumed that all standard sequence consumers (including list, of course)
would intercept
> the StopIteration of a sequence given them in the form of a generator
expression, so your
> lyst example would have an analogue for other sequence consumers as well,
right?
> I.e., there's not a hidden li
On Fri, 01 Apr 2005 16:34:32 GMT, "Raymond Hettinger" <[EMAIL PROTECTED]> wrote:
>[Peter Otten]
>> a StopIteration raised in a generator expression
>> silently terminates that generator:
>>
>> >>> def stop(): raise StopIteration
>> ...
>> >>> list(i for i in range(10) if i < 5 or stop())
>> [0, 1,
[Peter Otten]
> a StopIteration raised in a generator expression
> silently terminates that generator:
>
> >>> def stop(): raise StopIteration
> ...
> >>> list(i for i in range(10) if i < 5 or stop())
> [0, 1, 2, 3, 4]
>
> In a list comprehension, on the other hand, it is propagated:
>
> >>> [i for
Peter Otten wrote:
> To confuse a newbies and old hands alike, Bengt Richter wrote:
>
> > Need something more straightforward, e.g., a wrapped one-liner:
> >
> > >>> def guess(n=3): print ("You're right!", 'No more tries for
> > >>> you!!!')[n-1 in
> > ...(x for x in xrange(n) for t in [raw_
Peter Otten wrote:
To confuse a newbies and old hands alike, Bengt Richter wrote:
got me for one:)
To make it a bit clearer, a StopIteration raised in a generator expression
silently terminates that generator:
*any* exception raised from a generator, terminates the generator
jfj
--
http://mail.pyt
16 matches
Mail list logo