import collections


def partition_params(all_experiments, split_key):
    """
    Partitions parameters into groups according to split_key

    Args:
        all_experiments: An iterator through ExperimentLog objects
        split_key: A string (or tuple) of keys to group by. 

    Returns:
        A dictionary from values of split_key to lists of ExperimentLog objects
    """
    partition_params = collections.defaultdict(list)
    for exp in all_experiments:
        if isinstance(split_key, (list, tuple)):
            exp_key_val = tuple((exp.params[k] for k in split_key))
        else:
            exp_key_val = exp.params[split_key]
        partition_params[exp_key_val].append(exp)
    return partition_params