import json


def load_dict(dict_path, array_key=False):
    """
    Args:
        dict_path: The path to a json dictionary
        array_key: If true the parser will consider the first element in a sublist at the key {_:[K,...,V],...}.
                    Otherwise it will parse as {K:V,...} or {K:[...,V],...}
    Returns:
        A dictionary corresponding to the info from the file. If the file was formatted with arrays as the values for a
         key, the last element of the array is used as the value for the key in the parsed dictionary
    """
    parsed = None
    if dict_path is not None:
        with open(dict_path) as f:
            parsed = json.load(f)
            for key in list(parsed.keys()):
                entry = parsed[key]
                if type(entry) == list:
                    if array_key:
                        val = parsed.pop(key)
                        parsed[val[0]] = val[-1]
                    else:
                        parsed[key] = parsed[key][-1]
    return parsed