Return sequence (list) of dictionaries, transposed into a dictionary of sequences (lists)

    >>> sorted(sod_transposed([{'c': 1, 'cm': 'P'}, {'c': 1, 'ct': 2, 'cm': 6, 'cn': 'MUS'},
    ...                        {'c': 1, 'cm': 'Q', 'cn': 'ROM'}], filler=0).items())
    [('c', [1, 1, 1]), ('cm', ['P', 6, 'Q']), ('cn', [0, 'MUS', 'ROM']), ('ct', [0, 2, 0])]
    >>> sorted(sod_transposed(({'c': 1, 'cm': 'P'}, {'c': 1, 'ct': 2, 'cm': 6, 'cn': 'MUS'},
    ...                        {'c': 1, 'cm': 'Q', 'cn': 'ROM'}),
    ...                       filler=0, align=0).items())
    [('c', [1, 1, 1]), ('cm', ['P', 6, 'Q']), ('cn', ['MUS', 'ROM']), ('ct', [2])]

def sod_transposed(seq_of_dicts, align=True, pad=True, filler=None):
    """Return sequence (list) of dictionaries, transposed into a dictionary of sequences (lists)

    >>> sorted(sod_transposed([{'c': 1, 'cm': 'P'}, {'c': 1, 'ct': 2, 'cm': 6, 'cn': 'MUS'},
    ...                        {'c': 1, 'cm': 'Q', 'cn': 'ROM'}], filler=0).items())
    [('c', [1, 1, 1]), ('cm', ['P', 6, 'Q']), ('cn', [0, 'MUS', 'ROM']), ('ct', [0, 2, 0])]
    >>> sorted(sod_transposed(({'c': 1, 'cm': 'P'}, {'c': 1, 'ct': 2, 'cm': 6, 'cn': 'MUS'},
    ...                        {'c': 1, 'cm': 'Q', 'cn': 'ROM'}),
    ...                       filler=0, align=0).items())
    [('c', [1, 1, 1]), ('cm', ['P', 6, 'Q']), ('cn', ['MUS', 'ROM']), ('ct', [2])]
    """
    result = {}
    if isinstance(seq_of_dicts, Mapping):
        seq_of_dicts = [seq_of_dicts]
    it = iter(seq_of_dicts)
    # if you don't need to align and/or fill, then just loop through and return
    if not (align and pad):
        for d in it:
            for k in d:
                result[k] = result.get(k, []) + [d[k]]
        return result
    # need to align and/or fill, so pad as necessary
    for i, d in enumerate(it):
        for k in d:
            result[k] = result.get(k, [filler] * (i * int(align))) + [d[k]]
        for k in result:
            if k not in d:
                result[k] += [filler]
    return result