BartC <[email protected]> writes:
> def case(*args):
> return any((arg == switch.value for arg in args))
def case(values):
return switch.value in values
> I used it in my benchmark to replace the if-else chain checking three
> lots of ranges:
>
> switch(c)
> if case(ord("A"),ord("B"),ord("C"),ord("D"),ord("E"),ord("F"),
> ord("G"),ord("H"),ord("I"),ord("J"),ord("K"),ord("L"),
> ord("M"),ord("N"),ord("O"),ord("P"),ord("Q"),ord("R"),
> ord("S"),ord("T"),ord("U"),ord("V"),ord("W"),ord("X"),
> ord("Y"),ord("Z")):
> upper+=1
Use a set instead of a big tuple:
uppers = { ord("A"), ord("B"), ... ord("Z") }
...
if case(uppers):
upper += 1
--
https://mail.python.org/mailman/listinfo/python-list