[Alan Kennedy] >> On jython 2.1, I use something like this >> >> #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= >> try: >> enumerate >> except NameError: >> def enumerate(iterable): >> results = [] ; ix = 0 >> for item in iterable: >> results.append( (ix, item) ) >> ix = ix+1 >> return results
[Fredrik Lundh] > at least in CPython, using a user-defined enumerate function is a bit > slower than using the built-in version. Who's using a user-defined enumerate on cpython? The above code only defines a user-defined enumerate when the built-in one doesn't exist, i.e. on jython, which raises NameError on reference to the non-existent enumerate. On cpython, the reference to enumerate doesn't generate a NameError, therefore the user-supplied version never gets defined, and the builtin is used. regards, -- alan kennedy ------------------------------------------------------ email alan: http://xhaus.com/contact/alan -- http://mail.python.org/mailman/listinfo/python-list