[Tutor] synchronized enumerate

Chris or Leslie Smith smiles at worksmail.net
Tue Dec 20 06:44:57 CET 2005

Kent wrote:
| Take a look at this thread on c.l.py for some discussion and
| possibilities. The part you 
| are interested in starts around message 14.
| http://groups.google.com/group/comp.lang.python/browse_frm/thread/ab1658dca4023e2b?hl=en&
After looking at that I found something on python-dev that showed how to create an object that is sliceable but returns a slice object: sslice[::-1] --> slice(None, None, -1). It would be interesting if a single object could be sliced or accessed as a function, but I'm not sure that is possible. If it were, you could do:

sslice(3) --> slice(None, 3, None)
sslice[:3]--> slice(None, 3, None)

Here's the code from python-dev:

class MetaSlice(object):
        def __getitem__(cls, item):
                return item
        def __init__(self, *args, **kw):
                return super(MetaSlice,self).__init__(self, *args, **kw)
class sslice(slice):

Anway, after seeing that, I decided to re-write the enumerate so it takes a slice argument and then I get the start and step values from that rather than having those passed in as arguments. I also initiated the discussion on python-dev (and they said that comp.lang.python was a better place for it) and c.l.p. The updated version of the enuerate can be found on compl.lang.python under "synchronized enumerate" at  


Thanks for the pointers and advice, Kent.


More information about the Tutor mailing list