import collections


def decode_attribute_idx_data(submissions):
    """Return a list of dicts representing the decoded data.

    Some of the form data returned from MTurk is encoded as
    ``"attribute-idx": value`` mappings, where attribute represents the
    attribute encoded and idx is the index of the problem instance. This
    function takes a list of dictionaries in the attribute-idx style and
    decodes them into the individual problem instances.

    Parameters
    ----------
    submissions : List[Dist[str, str]]
        The data to decode. Each submission must be formatted in the
        attribute-idx style.

    Returns
    -------
    List[Dist[str, str]]
        A list of dictionaries with each instance separated out
        individually.
    """
    rows = []
    for submission in submissions:
        idx_to_row = collections.defaultdict(dict)
        for k, v in submission.items():
            attribute, idx = k.rsplit('-', 1)
            idx_to_row[idx][attribute] = v

        rows.extend(idx_to_row.values())

    return rows