count strangeness
James Stroud
jstroud at mbi.ucla.edu
Sun May 22 02:56:36 EDT 2011
Peter Otten wrote:
> James Stroud wrote:
>> WTF?
>
> Put the code into a file, run it -- and be enlightened ;)
Compare the follower to the last.
tal 77% cat eraseme.py
#! /usr/bin/env python
class C:
def __init__(self):
self.data = []
def doit(self, count=[0]):
for c in self.data:
c.doit()
count[0] += 1
print count[0]
c = C()
c.data.extend([C() for i in xrange(10)])
c.doit()
tal 78% python2.7 eraseme.py
1
2
3
4
5
6
7
8
9
10
11
James
More information about the Python-list
mailing list