I have a variable I want to set depending on the values in three booleans. The most straight-forward way is an if statement followed by a series of elifs:
if a a
I'd go for the list/bits solution of @OscarRyz, @Clint and @Sven, but here's another one:
S1 = frozenset(['first', 'second', 'third', 'fourth'])
S2 = frozenset(['first', 'second', 'fifth', 'sixth'])
S3 = frozenset(['first', 'third', 'fifth', 'seventh'])
last = 'eighth'
empty = frozenset([])
def value(a, b, c):
for r in (a and S1 or empty) & (b and S2 or empty) & (c and S3 or empty):
return r
return last