Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Could be DRYer solution in Creative category for Voice TV Control by suic
class VoiceCommand(list):
def __init__(self, channels):
super().__init__(channels)
self._channel_index = 0
def first_channel(self):
return self.current_channel(0)
def last_channel(self):
return self.current_channel(-1)
def turn_channel(self, n):
return self.current_channel(n-1)
def _turn_by(self, n):
return self.current_channel((self._channel_index + n) % len(self))
def next_channel(self):
return self._turn_by(1)
def previous_channel(self):
return self._turn_by(-1)
def current_channel(self, channel_index=None):
if channel_index is not None:
self._channel_index = channel_index
return self[self._channel_index]
def is_exist(self, channel):
return ["No", "Yes"][channel in self]
July 17, 2018
Comments: