Siddharta wrote:
> Pythonic wrote:
>
>> * 2. Best solution (Pythonic)*
>>
>>
>>
> import itertools
> c = itertools.count(9)
> c.next()
>
>
>> 9
>>
>>
> c.next()
>
>
>> 10
>>
>>
>
> +1 Pythonic: iterto
Here is a way to do this when x is global. I don't recommend it, because
it modifies the global dictionary. Still it gives an effect closes to what
you want perhaps.
>>>incr = lambda x: globals().__setitem__('x',x+1)
>>>def f(): incr(x); return x
>>>x=10
>>>f()
11
>>>f()
12
>>>x
12
--Anand
On Fe
Pythonic wrote:
> * 2. Best solution (Pythonic)*
>
>
import itertools
c = itertools.count(9)
c.next()
> 9
>
c.next()
> 10
>
+1 Pythonic: itertools is the way to go
But if you really want to implement it yourself, you need to do
something l
hi
On Feb 18, 2008 4:09 PM, Ramaswamy, Vivek <[EMAIL PROTECTED]> wrote:
> Hello~
>
>
> >>> g=lambda m:lambda: ++m
> >>> incre=g(0)
> >>> incre()
> 0
> >>> incre()
> 0
> >>> incre()
> 0
> >>>
>
> I would want each call to incre() increase the value by one.
>
i dont understand why you call incre()(
Ramaswamy, Vivek wrote:
> Hello~
>
> I am relatively new to python, but I was trying to auto increment a
> variable through using the lambda anonymous function, but unfortunately
> I am un-able to get the desired result. Please let me know where I am
> going wrong
> g=lambda m:lambda: ++m
> incre=
Hello~
I am relatively new to python, but I was trying to auto increment a
variable through using the lambda anonymous function, but unfortunately
I am un-able to get the desired result. Please let me know where I am
going wrong:
>>> g=lambda m:lambda: ++m
>>> incre=g(0)
>>> incre()
0
>>> incre(