Push Me Pull You

Python

GNU GPL

Download (right click, save as, rename as appropriate)

Embed

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
class PushMePullYou():
    def __init__(self, list):
        self.list = list
        self.index = 0
        self.total = len(list) - 1
        
    def next(self):
        if self.index >= self.total:
            self.index = 0
        else:
            self.index += 1

        return self.list[self.index]

    def previous(self):
        if self.index <= 0:
            self.index = self.total
        else:
            self.index -= 1

        return self.list[self.index]