def parse_to_dicts(lines, containers):
    """
    Parses a list of lines into tuples places in the given containers.

    The lists of lines has the following format

    token1: tval1
    key1: val11
    key2: val12
    token1: tval2
    key1: val21
    key2: val22



    :param lines:
    :param containers: a dictionary { token : array_instance}
    :return:
    """

    pairs = [(a, b.strip()) for a, b in (m.split(':', 1) for m in lines)]
    item = {}
    kind, name = None, None
    for j in range(0, len(pairs)):
        if pairs[j][0] in containers.keys():
            if j != 0:
                containers[kind].append((name, item))
            item = {}
            kind = pairs[j][0]
            name = pairs[j][1]
        else:
            item[pairs[j][0]] = pairs[j][1]
    if kind is not None:
        containers[kind].append((name, item))

    return containers