Skip to content

Instantly share code, notes, and snippets.

@kezabelle
Created October 5, 2015 20:44
Show Gist options
  • Save kezabelle/cb40ad1c41c9b86de1da to your computer and use it in GitHub Desktop.
Save kezabelle/cb40ad1c41c9b86de1da to your computer and use it in GitHub Desktop.
Convert a series of True/False items into a single number...
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