I have a piece of my code where I\'m supposed to create a switchboard. I want to return a list of all the switches that are on. Here \"on\" will equal True and
You can use filter for it:
filter(lambda x: self.states[x], range(len(self.states)))
The range here enumerates elements of your list and since we want only those where self.states is True, we are applying a filter based on this condition.
For Python > 3.0:
list(filter(lambda x: self.states[x], range(len(self.states))))