Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
define a getter solution in Clear category for Voice TV Control by quarkov
class VoiceCommand:
def __init__(self, CHANNELS):
self.channels = {pos+1: channel for (pos, channel) in enumerate(CHANNELS)}
self.count = len(CHANNELS)
self.pos = 1
def getter(self, item):
self.pos = item
return self.channels[self.pos]
def turn_channel(self, N):
return self.getter(N) if N <= self.count else f"{N} not in list"
def first_channel(self):
return self.turn_channel(1)
def last_channel(self):
return self.turn_channel(self.count)
def next_channel(self):
return self.turn_channel(self.pos+1) if self.pos < self.count else self.turn_channel(1)
def previous_channel(self):
return self.turn_channel(self.pos-1) if self.pos > 1 else self.turn_channel(self.count)
def current_channel(self):
return self.channels[self.pos]
def is_exist(self, channel):
return "Yes" if (channel in self.channels or channel in self.channels.values()) else "No"
March 15, 2019
Comments: