"John Roth" wrote: > Unfortunately it doesn't work: getitem can be defined for > a class that acts like a dictionary: that is, the items are > not integers, let alone integers that extend in a strict > sequence from 0.
This is true, but that's the current behaviour of iterators for classes that define __getitem__ without __iter__: class AnIterable(object): def __init__(self, it): self._it = it def __getitem__(self,i): return self._it[i] >>> x = AnIterable(dict(a=1,b=2)) >>> list(x) KeyError: 0 George -- http://mail.python.org/mailman/listinfo/python-list