This file contains hidden or 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 multisplit(string, *args): | |
| """ | |
| Will split 'string' using all of the additional arguments to multisplit. | |
| Will then filter out any instances of empty strings in the resultant list | |
| For example | |
| result = multisplit("a, b c,d e", ",", " ") # Split on both commas and spaces | |
| result == ["a", "b", "c", "d", "e"] |
This file contains hidden or 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 sanitize_dict_keys(dictionary, character_replacement_dict): | |
| """ | |
| Inspect every key in an arbitrarily nested dict ('dictionary') | |
| for the existence of any of the keys in 'character_replacement_dict.' | |
| Each instance will be replaced by the corresponding value in 'character_replacement_dict.' | |
| NOTE: sanitize_dict_keys() will properly sanitize an arbitrarily nested dict | |
| with values that are or inherit from either primitives, dicts, lists, tuples or sets. | |
| This type check is done using the 'isinstance()' function. |
This file contains hidden or 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 verify_dict_path(dictionary, *args): | |
| """ | |
| Verify that 'dictionary' contains nested members consistent with the additional arguments to 'verify_dict_path' in order | |
| e.g. For the_dict = {"a" : {"b" : {"c" : 3}}} | |
| verify_dict_path(the_dict, "a", "b", "c") == True | |
| verify_dict_path(the_dict, "a", "b") == True | |
| verify_dict_path(the_dict, "a", "b", "c", "d") == False | |
| verify_dict_path(the_dict, "a", "b", "e") == False | |
| :param dictionary: A dictionary |
This file contains hidden or 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
| # Author : John Carrell | |
| # | |
| # A memoize function to use as a decorator | |
| # | |
| # Memoization is caching the arguments to and result of a function. | |
| # Then, the next time that function is called with the same arguments the result is taken from the cache rather invoking the function. | |
| # Memoization is effective when executing the logic of a particularly function is expensive. | |
| # For instance, expensive calculations, network I/O or file access would be effective things to avoid if the yielded value won't or doesn't need to change. | |
| # | |
| # A detministic function is one where for a given input the same output is always produced. |
This file contains hidden or 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
| /** | |
| * Takes a dot notated object string ("root.child1.child2.child3") and converts it to square bracket notation ("root[child1][child2][child3]"). | |
| * | |
| * @param dot_string {string} | |
| * A string in dot notation. | |
| * * Must be of a non-zero length | |
| * * Must include at least one "." | |
| * * Must have more than one token | |
| * | |
| * @param include_single_quotes {boolean} |
NewerOlder