def sorted_alpha(sortme, unique=True):
    """
    Sorts a string alphabetically, but does (kind of) the opposite of
    the built-in ``sorted`` function.

    Sorted order is:

      * lowercase
      * uppercase
      * digits
      * punctuation

    Example:

    >>> sorted_alpha("aSD??fc?!")
    afcSD?!

    """
    upper, lower, digit, punctuation, passed = ([], [], [], [], [])
    passed = []
    for char in sortme:
        # skip duplicates
        if unique and char in passed:
            continue

        if char.isupper():
            upper.append(char)
        elif char.islower():
            lower.append(char)
        elif char.isdigit():
            digit.append(char)
        else:
            punctuation.append(char)

        passed.append(char)

    return ''.join(lower + upper + digit + punctuation)