Re: Proposal: [... for ... while cond(x)]

2013-09-26 Thread Nick Mellor
On Friday, 27 September 2013 00:39:30 UTC+10, Nick Mellor wrote: [snip] > for x in xs: > if not emit: > if cond(x): > emit = True > else: > yield e(x) > Oops! for x in xs: if not emit: if cond(x): emit = True yield e(x) els

Re: Proposal: [... for ... while cond(x)]

2013-09-26 Thread Nick Mellor
Hi all, It might be a risk that we create some hairy or subtle semantics, but perhaps this idea has legs. The 'pythonic' syntax is very attractive. # skip the silence at the start data = (amp for amp in signal from abs(amp) > 0.05) # drop files that are less than 600 bytes # (already sorted int

Re: Proposal: [... for ... while cond(x)]

2006-08-08 Thread Neil Hodgson
Eighty: > So does no one have a comment on this? Similar proposals have appeared before (such as on python-dev about a year ago) and haven't attracted much positive comment. The benefits appear to be small compared to the cost of making the language larger. You could try the formal route

Re: Proposal: [... for ... while cond(x)]

2006-08-08 Thread Eighty
Terry Reedy wrote: > whereas the analogous expansion of your proposal > > for x in xs: > while cond(x): > yield e(x) > > is an infinite loop and not at all what you mean. You're right. The syntax is ambiguous. I agree it's not a good idea, now. :) > x for x in xs while cond(x) if blah(x)

Re: Proposal: [... for ... while cond(x)]

2006-08-08 Thread Terry Reedy
"Eighty" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Eighty wrote: >> I suggest a new extension of the list comprehension syntax: >> >> [x for x in xs while cond(x)] This does not work. e(x) for x in xs if cond(x) is an abbreviation of for x in xs: if cond(x) yield e

Re: Proposal: [... for ... while cond(x)]

2006-08-08 Thread Eighty
Eighty wrote: > I suggest a new extension of the list comprehension syntax: > > [x for x in xs while cond(x)] > > which would be equivalent to > > list(itertools.takewhile(cond, xs)) > > + Since Python favors list comprehensions over map, filter, and reduce, > this would be the preferred way to do

Re: Proposal: [... for ... while cond(x)]

2006-08-07 Thread Rick Zantow
Duncan Booth <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > Diez B. Roggisch wrote: > >>> No, the list comprehension lets you write an expression directly >>> avoiding a function call, and it also allows you to add in a >>> condition which can be used to filer the sequence. Your proposal

Re: Proposal: [... for ... while cond(x)]

2006-08-07 Thread Duncan Booth
Slawomir Nowaczyk wrote: > #> No, the list comprehension lets you write an expression directly > #> avoiding a function call, and it also allows you to add in a > #> condition which can be used to filer the sequence. > > I am not sure if I understand you correctly, but... Does it? > a = [0

Re: Proposal: [... for ... while cond(x)]

2006-08-07 Thread Duncan Booth
Diez B. Roggisch wrote: >> No, the list comprehension lets you write an expression directly >> avoiding a function call, and it also allows you to add in a >> condition which can be used to filer the sequence. Your proposal adds >> nothing. > > It does. Consider this: > > whatever = [x for x in

Re: Proposal: [... for ... while cond(x)]

2006-08-06 Thread Diez B. Roggisch
> No, the list comprehension lets you write an expression directly avoiding a > function call, and it also allows you to add in a condition which can be > used to filer the sequence. Your proposal adds nothing. It does. Consider this: whatever = [x for x in xrange(10) while x < 10] T

Re: Proposal: [... for ... while cond(x)]

2006-08-06 Thread Hugo Ferreira
I actually like the proposal...If the argument to remove map, lambda and filter can be that list comprehension is more "readable", then why can't this one also use it?Which reminds me this discussion: http://awkly.org/archive/can-python-take-advantage-of-mapreduce/ Cheers!HugoOn 8/6/06, Slawomir N

Re: Proposal: [... for ... while cond(x)]

2006-08-06 Thread Slawomir Nowaczyk
On Sun, 06 Aug 2006 18:59:39 + (GMT) Duncan Booth <[EMAIL PROTECTED]> wrote: #> >> > I suggest a new extension of the list comprehension syntax: #> >> > #> >> > [x for x in xs while cond(x)] #> >> > #> >> > which would be equivalent to #> >> > #> >> > list(itertools.takewhile(cond, xs)) #> >>

Re: Proposal: [... for ... while cond(x)]

2006-08-06 Thread Duncan Booth
Eighty wrote: > > Duncan Booth wrote: >> Eighty wrote: >> >> > I suggest a new extension of the list comprehension syntax: >> > >> > [x for x in xs while cond(x)] >> > >> > which would be equivalent to >> > >> > list(itertools.takewhile(cond, xs)) >> > >> >> What would this syntax offer that: >>

Re: Proposal: [... for ... while cond(x)]

2006-08-06 Thread Eighty
Duncan Booth wrote: > Eighty wrote: > > > I suggest a new extension of the list comprehension syntax: > > > > [x for x in xs while cond(x)] > > > > which would be equivalent to > > > > list(itertools.takewhile(cond, xs)) > > > > What would this syntax offer that: > >[x for x in takewhile(cond,

Re: Proposal: [... for ... while cond(x)]

2006-08-06 Thread Duncan Booth
Eighty wrote: > I suggest a new extension of the list comprehension syntax: > > [x for x in xs while cond(x)] > > which would be equivalent to > > list(itertools.takewhile(cond, xs)) > What would this syntax offer that: [x for x in takewhile(cond, xs)] doesn't currently offer? (Apart, th

Proposal: [... for ... while cond(x)]

2006-08-06 Thread Eighty
I suggest a new extension of the list comprehension syntax: [x for x in xs while cond(x)] which would be equivalent to list(itertools.takewhile(cond, xs)) + Since Python favors list comprehensions over map, filter, and reduce, this would be the preferred way to do this + "Takewhile operations"