All pastes #597391 Raw Edit

Stuff

public text v1 · immutable
#597391 ·published 2007-06-30 16:09 UTC
rendered paste body
class FlatListAccessor:
    def __init__(self, l, width):
        self.list = l
        self.width = width
    
    def __getitem__(self, coordinates):
        x, y = coordinates
        return self.list[x+self.width*y]



used like this:

>>> data = FlatListAccessor([0,0,0,0,1,2,0,2,4], 3)
>>> data[0,0]
0
>>> data[0,1]
0
>>> data[1,1]
1
>>> data[2,2]
4