1st is a good solution, I do the same too. 2nd - you should consider assigning each power of day 2, so it’s easy to convert these numbers to binary using bin () and it's easy to compare, you just do &.
>>> mon, tue, wed, thu, fri, sat, sun = (pow(2, i) for i in range(7)) >>> bin(mon) '0b1' >>> bin(sun) '0b1000000' # create range: >>> x = mon | wed | fri >>> bin(x) '0b10101' # check if day is in range: >>> x & mon 1 >>> x & tue 0
The problem with bin is that you have to add 0 to the beginning to get a long string of length 7 char but you can also write your own version as follows:
bin = lambda n:"".join([str((n >> y) & 1) for y in range(7-1, -1, -1)])
source share