Top and Bottom Values [PEP: 326]
Paul Rubin
http
Thu Sep 28 06:29:49 EDT 2006
Antoon Pardon <apardon at forel.vub.ac.be> writes:
> It is something worth investigating, but I'm not sure it
> will suite my purpose. You see I have a table module,
> a table is like a list except the base index doesn't need
> to be 0. So I could have a table that is indexable from
> sys.maxint - 3 to sys.maxint + 7. I'm not sure tbl[:Top]
> would do what it is supposed to do in those circumstances.
Top = object()
class Table(list):
def __getitem__(self, n):
get = super(Table, self).__getitem__
if n is Top:
return get(-1)
return get(n - self.baseindex)
a=Table(range(9))
a.baseindex = 3
>>> print a[5], a[Top]
2 8
More information about the Python-list
mailing list