Created
October 5, 2015 20:44
-
-
Save kezabelle/cb40ad1c41c9b86de1da to your computer and use it in GitHub Desktop.
Convert a series of True/False items into a single number...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def truthynumber(*args): | |
""" | |
>>> truthynumber(True, True) | |
3 | |
>>> truthynumber(True, False, 1, 3, True) | |
5 | |
""" | |
ints = (str(int(arg)) for arg in args | |
if arg is True or arg is False) | |
bin_ints = ''.join(ints) | |
return int(bin_ints, 2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment