Aug-25-2019, 03:58 PM
(Aug-24-2019, 08:16 PM)perfringo Wrote: ndc85430 idea expressed in code:
>>> spam = True >>> spam = not spam >>> spam False >>> spam = not spam >>> spam TrueAnother possibility is to use itertools.cycle(). This is useful, if there are more than two values to flip:
>>> from itertools import cycle >>> switch = cycle([True, False]).__next__ >>> spam = switch() >>> spam True >>> spam = switch() >>> spam False >>> spam = switch() >>> spam True >>> switch = cycle(['ON', 'STANDBY', 'OFF']).__next__ >>> spam = switch() >>> spam 'ON' >>> spam = switch() >>> spam 'STANDBY' >>> spam = switch() >>> spam 'OFF' >>> spam = switch() >>> spam 'ON'
Thank you! That looks super useful!