class CircleList(list):
"""A list to circle throught""" # itertools.circle only goes one way
def __init__(self, l, i=0, stop=None):
super(CircleList, self).__init__(l)
self.i = i
self.stop = stop
def current(self):
return self[self.i]
def previous(self):
self.i -= 1
if self.i < 0:
self.i = 0 if self.stop else len(self)-1
return self[self.i]
def next(self):
self.i += 1
if self.i > len(self)-1:
self.i = len(self)-1 if self.stop else 0
return self[self.i]
python
<iframe width="100%" height="506" src="http://ginkobox.fr/vamp/index.php?embed=55c51d182921a" type="text/html"></iframe>
Text only - Permalink - Snippet public post date 07/08/2015