[snip]
>> 2. side effect of (maybe) leaking the iterator variable "value" into
>> the code following the loop (if the iterator is not empty).
>
> So? it is sometime useful.
Except that you can't guarantee that it will be set since the for loop
will not execute if the iterable is empty.
>>
>> I ca
On 2/1/2010 3:05 PM, Arnaud Delobelle wrote:
You have itertools.consume which is close to what you want:
consume(imap(func, iterable)) # 2.x
consume(map(func, iterable)) # 3.x
Consume is not in itertools. It is one of many recipes in the doc
(9.7.2). For exhausting an iterator, co
On 2/1/2010 11:50 AM, Gerald Britton wrote:
Hi -- I have many sections of code like this:
for value in value_iterator:
value_function(value)
I noticed that this does two things I don't like:
1. looks up "value_function" and "value" for each iteration, but
"value_function" doesn'
2010/2/1 Gerald Britton :
> Hi -- I have many sections of code like this:
>
> for value in value_iterator:
> value_function(value)
>
> I noticed that this does two things I don't like:
>...
> --
> Gerald Britton
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Hi,
just to ad
[snip[
> You have itertools.consume which is close to what you want:
>
> consume(imap(func, iterable)) # 2.x
>
> consume(map(func, iterable)) # 3.x
>
> HTH
It does! Though in my case this is simpler:
deque(imap(func, iterable), 0)
since the recipe for consume just calls deque anyway w
Gerald Britton writes:
> Hi -- I have many sections of code like this:
>
> for value in value_iterator:
> value_function(value)
>
> I noticed that this does two things I don't like:
>
> 1. looks up "value_function" and "value" for each iteration, but
> "value_function" doesn't change
So.I'm wondering if there is any interest in an apply() built-in
function that would work like map() does in 2.x (calls the function
with each value returned by the iterator) but return nothing. Maybe
"apply" isn't the best name; it's just the first one that occurred to
me.
Or is this just s
Hi -- I have many sections of code like this:
for value in value_iterator:
value_function(value)
I noticed that this does two things I don't like:
1. looks up "value_function" and "value" for each iteration, but
"value_function" doesn't change.
2. side effect of (maybe) leaking the