Last active
February 2, 2016 02:00
-
-
Save rfong/24dbdbe48985ec0011f1 to your computer and use it in GitHub Desktop.
useful python stuff I lug around
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
import itertools | |
def printable_percent(numerator, denominator, precision=2): | |
"""Truncated readable percentage""" | |
return ('%.' + str(precision) + 'f') % (numerator * 100.0 / denominator) | |
def generate_all_binary_states(keys): | |
""" | |
For testing, generate all True/False combinations for a set of keys. | |
Return a list of dictionaries {key: boolean} | |
""" | |
return [ | |
dict(zip(keys, combo)) for combo in | |
itertools.product((False, True), repeat=len(keys)) | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment