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
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
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
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)
"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
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
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
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
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
> 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
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
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))
#> >>
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:
>>
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,
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
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"
16 matches
Mail list logo