count strangeness
Peter Otten
__peter__ at web.de
Sun May 22 02:31:24 EDT 2011
James Stroud wrote:
> tal 65% python2.7
> Python 2.7.1 (r271:86832, May 21 2011, 22:52:14)
> [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> py> class C(object):
> ... def __init__(self):
> ... self.data = []
> ... def doit(self, count=0):
> ... for c in self.data:
> ... count += c.doit(count)
> ... count += 1
> ... print count
> ... return count
> ...
> py> c = C()
> py> c.data.extend([C() for i in xrange(10)])
> py> c.doit()
> 1
> 2
> 4
> 8
> 16
> 32
> 64
> 128
> 256
> 512
> 1024
> 1024
>
>
>
> WTF?
Put the code into a file, run it -- and be enlightened ;)
More information about the Python-list
mailing list