def split_to_comparable_groups(dicts, key_to_compare_over, key_filter=None): """Given a list of dicts, split into groups whose arguments (as determined by is_arg_key(), outdir is excluded) only differ by key_to_compare_over. Warning: O(N^2) where N is the number of arguments in the dicts. """ # Default: interested in arguments other than -outdir which always # changes if key_filter is None: key_filter = lambda k: (is_arg_key(k) and k != "-outdir") # List of keys of interest (from the first dict), assumes that all # dicts have the same keys. argument_dict_keys = [k for k, _ in dicts[0].items() if (key_filter(k) and k != key_to_compare_over)] # List of arg keys which are not constant accross dicts. n^2 in number # of entries in argument_dict_keys, should be fine. keys_which_differ = set([]) for k in argument_dict_keys: for d in dicts: for d2 in dicts: # If value differs or if key is not in one of the dicts # then it differs. try: if d[k] != d2[k]: keys_which_differ.add(k) except KeyError: keys_which_differ.add(k) print(keys_which_differ) comparable_groups = utils.split_up_stuff(dicts, keys_to_split_on=keys_which_differ) return comparable_groups