def seq_join(seq, val):
    """
    Flatten input sequence of lists into a single list. Insert separator
    value if not None.
    @param[in] seq sequence of lists
    @param[in] val separator value, will be put between sub-sequences in the
               resulting list if not None.
    @returns resulting flattened list
    """
    res = []
    for item in seq[:-1]:
        res.extend(item)
        if val is not None:
            res.append(val)
    res.extend(seq[-1])
    return res