def as_seq(x, seq_type=None):
    """
    If x is not a sequence, returns it as one. The seq_type argument allows the
    output type to be specified (defaults to list). If x is a sequence and
    seq_type is provided, then x is converted to seq_type.

    Arguments
    ---------
    x : seq or object

    seq_type : output sequence type
        If None, then if x is already a sequence, no change is made. If x
        is not a sequence, a list is returned.
    """
    if x is None:
        # None represents an empty sequence
        x = []
    elif not isinstance(x, (list, tuple, set, frozenset, dict)):
        # if x is not already a sequence (including dict), then make it one
        x = [x]

    if seq_type is not None and not isinstance(x, seq_type):
        # if necessary, convert x to the sequence type
        x = seq_type(x)

    return x