Message136824
"""
Changing the 'enumerate' doc string text from:
| (0, seq[0]), (1, seq[1]), (2, seq[2]), ...
to:
| (start, seq[0]), (start+1, seq[1]), (start+2, seq[2]), ...
would completely disambiguate the doc string at the modest cost of
sixteen additional characters, a small price for pellucid clarity.
The proposed changes to the formal documentation also seem to me to
be prudent, and I hope at this late writing, they have already been
committed.
I conclude with a code fragment for the edification of R. David Murray.
"""
class numerate(object):
"""
A demonstration of a plausible incorrect interpretation of
the 'enumerate' function's doc string and documentation.
"""
def __init__(self,seq,start=0):
self.seq=seq; self.index=start-1
try:
if seq.next: pass #test for iterable
for i in xrange(start): self.seq.next()
except:
if type(seq)==dict: self.seq=seq.keys()
self.seq=iter(self.seq[start:])
def next(self):
self.index+=1
return self.index,self.seq.next()
def __iter__(self): return self
if __name__ == "__main__":
#s=['spring','summer','autumn','winter']
s={'spring':'a','summer':'b','autumn':'c','winter':'d'}
#s=enumerate(s)#,2)
s=numerate(s,2)
for t in s: print t |
|
Date |
User |
Action |
Args |
2011-05-25 03:22:38 | phammer | set | recipients:
+ phammer, rhettinger, terry.reedy, eric.araujo, r.david.murray |
2011-05-25 03:22:38 | phammer | set | messageid: <1306293758.78.0.861420661473.issue11889@psf.upfronthosting.co.za> |
2011-05-25 03:22:38 | phammer | link | issue11889 messages |
2011-05-25 03:22:37 | phammer | create | |
|