Re: [BangPypers] BangPypers Digest, Vol 6, Issue 8

2008-02-18 Thread Pythonic
Siddharta wrote: > Pythonic wrote: > >> * 2. Best solution (Pythonic)* >> >> >> > import itertools > c = itertools.count(9) > c.next() > > >> 9 >> >> > c.next() > > >> 10 >> >> > > +1 Pythonic: iterto

Re: [BangPypers] BangPypers Digest, Vol 6, Issue 8

2008-02-18 Thread Anand Balachandran Pillai
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

Re: [BangPypers] BangPypers Digest, Vol 6, Issue 8

2008-02-18 Thread Siddharta
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

Re: [BangPypers] BangPypers Digest, Vol 6, Issue 8

2008-02-18 Thread Prashanth
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()(

Re: [BangPypers] BangPypers Digest, Vol 6, Issue 8

2008-02-18 Thread Pythonic
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=

Re: [BangPypers] BangPypers Digest, Vol 6, Issue 8

2008-02-18 Thread Ramaswamy, Vivek
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(