Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
33-liner: flat solution in Clear category for Voice TV Control by przemyslaw.daniel
class VoiceCommand:
def __init__(self, channels):
self.channels = channels
self.current = 0
def first_channel(self):
self.current = 0
return self.current_channel()
def last_channel(self):
self.current = len(self.channels) - 1
return self.current_channel()
def turn_channel(self, number):
self.current = number - 1
return self.current_channel()
def current_channel(self):
return self.channels[self.current]
def next_channel(self):
self.current = (self.current + 1) % len(self.channels)
return self.current_channel()
def previous_channel(self):
self.current = (self.current - 1) % len(self.channels)
return self.current_channel()
def is_exist(self, channel):
choice = ['No', 'Yes']
if isinstance(channel, str):
return choice[channel in self.channels]
return choice[0 <= channel < len(self.channels)]
July 28, 2018